From 8e7ad854e6e6e98641975f103dd38dc4a3116bab Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 2 Oct 2019 15:06:09 +0200 Subject: [PATCH 1/2] Add fdiv() function --- ext/standard/basic_functions.c | 6 +++ ext/standard/math.c | 18 +++++++ ext/standard/php_math.h | 1 + ext/standard/tests/math/fdiv.phpt | 78 +++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 ext/standard/tests/math/fdiv.phpt diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index ff12fceb73f2..4ba17f277309 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, x) + ZEND_ARG_INFO(0, y) +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..023ceeb1283f 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1296,6 +1296,24 @@ PHP_FUNCTION(fmod) } /* }}} */ +/* {{{ proto float fdiv(float x, float y) + Perform floating-point division of x / y with IEEE-754 semantics for division by zero. */ +#ifdef __clang__ +__attribute__((no_sanitize("float-divide-by-zero"))) +#endif +PHP_FUNCTION(fdiv) +{ + double num1, num2; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_DOUBLE(num1) + Z_PARAM_DOUBLE(num2) + ZEND_PARSE_PARAMETERS_END(); + + RETURN_DOUBLE(num1 / num2); +} +/* }}} */ + /* {{{ 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) From 382b91a5da1358c580219efabebd391f0e639e82 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 2 Oct 2019 17:04:47 +0200 Subject: [PATCH 2/2] Use $dividend and $divisor for argument names --- ext/standard/basic_functions.c | 4 ++-- ext/standard/math.c | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 4ba17f277309..bd0589737a6b 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1144,8 +1144,8 @@ ZEND_BEGIN_ARG_INFO(arginfo_fmod, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_fdiv, 0) - ZEND_ARG_INFO(0, x) - ZEND_ARG_INFO(0, y) + ZEND_ARG_INFO(0, dividend) + ZEND_ARG_INFO(0, divisor) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_intdiv, 0) diff --git a/ext/standard/math.c b/ext/standard/math.c index 023ceeb1283f..7c9502846a82 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1296,21 +1296,22 @@ PHP_FUNCTION(fmod) } /* }}} */ -/* {{{ proto float fdiv(float x, float y) - Perform floating-point division of x / y with IEEE-754 semantics for division by zero. */ +/* {{{ 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 num1, num2; + double dividend, divisor; ZEND_PARSE_PARAMETERS_START(2, 2) - Z_PARAM_DOUBLE(num1) - Z_PARAM_DOUBLE(num2) + Z_PARAM_DOUBLE(dividend) + Z_PARAM_DOUBLE(divisor) ZEND_PARSE_PARAMETERS_END(); - RETURN_DOUBLE(num1 / num2); + RETURN_DOUBLE(dividend / divisor); } /* }}} */