diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 index 3d00d88dda151..67952163aab76 100644 --- a/ext/standard/config.m4 +++ b/ext/standard/config.m4 @@ -338,7 +338,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 f6b3d5406ebe4..707f02dba735c 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -704,15 +704,26 @@ PHP_FUNCTION(log) 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)); } - if (base == 1) { +#endif + if (base == 10.0) { + RETURN_DOUBLE(log10(num)); + } + + 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)); } /* }}} */