diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index ff12fceb73f2..bd0589737a6b 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1143,6 +1143,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_fmod, 0) ZEND_ARG_INFO(0, y) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(arginfo_fdiv, 0) + ZEND_ARG_INFO(0, dividend) + ZEND_ARG_INFO(0, divisor) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO(arginfo_intdiv, 0) ZEND_ARG_INFO(0, dividend) ZEND_ARG_INFO(0, divisor) @@ -2287,6 +2292,7 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(base_convert, arginfo_base_convert) PHP_FE(number_format, arginfo_number_format) PHP_FE(fmod, arginfo_fmod) + PHP_FE(fdiv, arginfo_fdiv) PHP_FE(intdiv, arginfo_intdiv) #ifdef HAVE_INET_NTOP PHP_RAW_NAMED_FE(inet_ntop, zif_inet_ntop, arginfo_inet_ntop) diff --git a/ext/standard/math.c b/ext/standard/math.c index f903615d7575..7c9502846a82 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1296,6 +1296,25 @@ PHP_FUNCTION(fmod) } /* }}} */ +/* {{{ proto float fdiv(float dividend, float divisor) + Perform floating-point division of dividend / divisor + with IEEE-754 semantics for division by zero. */ +#ifdef __clang__ +__attribute__((no_sanitize("float-divide-by-zero"))) +#endif +PHP_FUNCTION(fdiv) +{ + double dividend, divisor; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_DOUBLE(dividend) + Z_PARAM_DOUBLE(divisor) + ZEND_PARSE_PARAMETERS_END(); + + RETURN_DOUBLE(dividend / divisor); +} +/* }}} */ + /* {{{ proto int intdiv(int dividend, int divisor) Returns the integer quotient of the division of dividend by divisor */ PHP_FUNCTION(intdiv) diff --git a/ext/standard/php_math.h b/ext/standard/php_math.h index 39751a7f8963..e85fd120f2c6 100644 --- a/ext/standard/php_math.h +++ b/ext/standard/php_math.h @@ -59,6 +59,7 @@ PHP_FUNCTION(octdec); PHP_FUNCTION(base_convert); PHP_FUNCTION(number_format); PHP_FUNCTION(fmod); +PHP_FUNCTION(fdiv); PHP_FUNCTION(deg2rad); PHP_FUNCTION(rad2deg); PHP_FUNCTION(intdiv); diff --git a/ext/standard/tests/math/fdiv.phpt b/ext/standard/tests/math/fdiv.phpt new file mode 100644 index 000000000000..dd50cfdb7889 --- /dev/null +++ b/ext/standard/tests/math/fdiv.phpt @@ -0,0 +1,78 @@ +--TEST-- +fdiv() function +--FILE-- + +--EXPECT-- +float(3.3333333333333) +float(3.3333333333333) +float(-4) +float(-4) + +float(INF) +float(-INF) +float(-INF) +float(INF) + +float(INF) +float(-INF) +float(-INF) +float(INF) + +float(NAN) +float(NAN) +float(NAN) +float(NAN) + +float(NAN) +float(NAN) +float(NAN) +float(NAN) + +float(0) +float(-0) +float(-0) +float(0) + +float(NAN) +float(NAN) +float(NAN) +float(NAN) +float(NAN)