com php-src: Improved logarithm of base 2 and 10 of standard math functions: ext/standard/config.m4 ext/standard/math.c

From: Date: Mon, 28 Apr 2014 17:58:10 +0000
Subject: com php-src: Improved logarithm of base 2 and 10 of standard math functions: ext/standard/config.m4 ext/standard/math.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-79864@lists.php.net to get a copy of this message
Commit: b547e1358d3846fad4cd0c86e2d2e9f5a9039b35 Author: Marc Bennewitz <marc-bennewitz@arcor.de> Mon, 28 Apr 2014 19:58:10 +0200 Parents: 03c703b8bd55679edf30fe17529fab0c2281b01f Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b547e1358d3846fad4cd0c86e2d2e9f5a9039b35 Log: Improved logarithm of base 2 and 10 of standard math functions Changed paths: M ext/standard/config.m4 M ext/standard/math.c Diff: diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 index c1f5aff..e1f9941 100644 --- a/ext/standard/config.m4 +++ b/ext/standard/config.m4 @@ -337,7 +337,7 @@ fi dnl dnl Check for available functions dnl -AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p hypot glob strfmon nice fpclass isinf isnan mempcpy strpncpy) +AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p log2 hypot glob strfmon nice fpclass isinf isnan mempcpy strpncpy) AC_FUNC_FNMATCH dnl diff --git a/ext/standard/math.c b/ext/standard/math.c index 72f6d51..b33b6e2 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -697,22 +697,35 @@ PHP_FUNCTION(log1p) PHP_FUNCTION(log) { double num, base = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|d", &num, &base) == FAILURE) { return; } + if (ZEND_NUM_ARGS() == 1) { RETURN_DOUBLE(log(num)); } - if (base <= 0.0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "base must be greater than 0"); - RETURN_FALSE; + +#ifdef HAVE_LOG2 + if (base == 2.0) { + RETURN_DOUBLE(log2(num)); + } +#endif + + if (base == 10.0) { + RETURN_DOUBLE(log10(num)); } - if (base == 1) { + + if (base == 1.0) { RETURN_DOUBLE(php_get_nan()); - } else { - RETURN_DOUBLE(log(num) / log(base)); } + + if (base <= 0.0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "base must be greater than 0"); + RETURN_FALSE; + } + + RETURN_DOUBLE(log(num) / log(base)); } /* }}} */

« previous php.cvs (#79864) next »