summaryrefslogtreecommitdiff
path: root/ext/standard/math.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/math.c')
-rw-r--r--ext/standard/math.c87
1 files changed, 53 insertions, 34 deletions
diff --git a/ext/standard/math.c b/ext/standard/math.c
index eaf4793ba6..6f7bede332 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -25,6 +25,7 @@
#include "php_math.h"
#include "zend_multiply.h"
#include "zend_exceptions.h"
+#include "zend_portability.h"
#include <math.h>
#include <float.h>
@@ -239,7 +240,7 @@ static double php_acosh(double x)
if (x >= 1) {
return log(x + sqrt(x * x - 1));
} else {
- return (DBL_MAX+DBL_MAX)-(DBL_MAX+DBL_MAX);
+ return ZEND_NAN;
}
# else
return(log(x + sqrt(x * x - 1)));
@@ -276,7 +277,7 @@ static double php_log1p(double x)
*/
static double php_expm1(double x)
{
-#if !defined(PHP_WIN32) && !defined(NETWARE)
+#ifndef PHP_WIN32
return(expm1(x));
#else
return(exp(x) - 1);
@@ -361,9 +362,12 @@ PHP_FUNCTION(round)
zend_long mode = PHP_ROUND_HALF_UP;
double return_val;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|ll", &value, &precision, &mode) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 3)
+ Z_PARAM_ZVAL(value)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_LONG(precision)
+ Z_PARAM_LONG(mode)
+ ZEND_PARSE_PARAMETERS_END();
if (ZEND_NUM_ARGS() >= 2) {
#if SIZEOF_ZEND_LONG > SIZEOF_INT
@@ -622,9 +626,10 @@ PHP_FUNCTION(pow)
{
zval *zbase, *zexp;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/z/", &zbase, &zexp) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 2)
+ Z_PARAM_ZVAL(zbase)
+ Z_PARAM_ZVAL(zexp)
+ ZEND_PARSE_PARAMETERS_END();
pow_function(return_value, zbase, zexp);
}
@@ -707,7 +712,7 @@ PHP_FUNCTION(log)
}
if (base == 1.0) {
- RETURN_DOUBLE(php_get_nan());
+ RETURN_DOUBLE(ZEND_NAN);
}
if (base <= 0.0) {
@@ -951,7 +956,7 @@ PHPAPI zend_string * _php_math_zvaltobase(zval *arg, int base)
char buf[(sizeof(double) << 3) + 1];
/* Don't try to convert +/- infinity */
- if (fvalue == HUGE_VAL || fvalue == -HUGE_VAL) {
+ if (fvalue == ZEND_INFINITY || fvalue == -ZEND_INFINITY) {
php_error_docref(NULL, E_WARNING, "Number too large");
return ZSTR_EMPTY_ALLOC();
}
@@ -977,9 +982,10 @@ PHP_FUNCTION(bindec)
{
zval *arg;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ZVAL(arg)
+ ZEND_PARSE_PARAMETERS_END();
+
convert_to_string_ex(arg);
if (_php_math_basetozval(arg, 2, return_value) == FAILURE) {
RETURN_FALSE;
@@ -993,9 +999,10 @@ PHP_FUNCTION(hexdec)
{
zval *arg;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ZVAL(arg)
+ ZEND_PARSE_PARAMETERS_END();
+
convert_to_string_ex(arg);
if (_php_math_basetozval(arg, 16, return_value) == FAILURE) {
RETURN_FALSE;
@@ -1009,9 +1016,10 @@ PHP_FUNCTION(octdec)
{
zval *arg;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ZVAL(arg)
+ ZEND_PARSE_PARAMETERS_END();
+
convert_to_string_ex(arg);
if (_php_math_basetozval(arg, 8, return_value) == FAILURE) {
RETURN_FALSE;
@@ -1026,9 +1034,10 @@ PHP_FUNCTION(decbin)
zval *arg;
zend_string *result;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ZVAL(arg)
+ ZEND_PARSE_PARAMETERS_END();
+
convert_to_long_ex(arg);
result = _php_math_longtobase(arg, 2);
RETURN_STR(result);
@@ -1042,9 +1051,10 @@ PHP_FUNCTION(decoct)
zval *arg;
zend_string *result;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ZVAL(arg)
+ ZEND_PARSE_PARAMETERS_END();
+
convert_to_long_ex(arg);
result = _php_math_longtobase(arg, 8);
RETURN_STR(result);
@@ -1058,9 +1068,10 @@ PHP_FUNCTION(dechex)
zval *arg;
zend_string *result;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ZVAL(arg)
+ ZEND_PARSE_PARAMETERS_END();
+
convert_to_long_ex(arg);
result = _php_math_longtobase(arg, 16);
RETURN_STR(result);
@@ -1075,9 +1086,11 @@ PHP_FUNCTION(base_convert)
zend_long frombase, tobase;
zend_string *result;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "zll", &number, &frombase, &tobase) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(3, 3)
+ Z_PARAM_ZVAL(number)
+ Z_PARAM_LONG(frombase)
+ Z_PARAM_LONG(tobase)
+ ZEND_PARSE_PARAMETERS_END();
convert_to_string_ex(number);
if (frombase < 2 || frombase > 36) {
@@ -1130,6 +1143,11 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
return tmpbuf;
}
+ /* Check if the number is no longer negative after rounding */
+ if (is_negative && d == 0) {
+ is_negative = 0;
+ }
+
/* find decimal point, if expected */
if (dec) {
dp = strpbrk(ZSTR_VAL(tmpbuf), ".,");
@@ -1283,9 +1301,10 @@ PHP_FUNCTION(intdiv)
{
zend_long dividend, divisor;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &dividend, &divisor) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 2)
+ Z_PARAM_LONG(dividend)
+ Z_PARAM_LONG(divisor)
+ ZEND_PARSE_PARAMETERS_END();
if (divisor == 0) {
zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Division by zero");