Skip to content

Commit 37e91cc

Browse files
committed
Merge branch 'pull-request/658'
2 parents e644e66 + b547e13 commit 37e91cc

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

ext/standard/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ fi
338338
dnl
339339
dnl Check for available functions
340340
dnl
341-
AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p hypot glob strfmon nice fpclass isinf isnan mempcpy strpncpy)
341+
AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p log2 hypot glob strfmon nice fpclass isinf isnan mempcpy strpncpy)
342342
AC_FUNC_FNMATCH
343343

344344
dnl

ext/standard/math.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -661,22 +661,35 @@ PHP_FUNCTION(log1p)
661661
PHP_FUNCTION(log)
662662
{
663663
double num, base = 0;
664-
664+
665665
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|d", &num, &base) == FAILURE) {
666666
return;
667667
}
668+
668669
if (ZEND_NUM_ARGS() == 1) {
669670
RETURN_DOUBLE(log(num));
670671
}
671-
if (base <= 0.0) {
672-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "base must be greater than 0");
673-
RETURN_FALSE;
672+
673+
#ifdef HAVE_LOG2
674+
if (base == 2.0) {
675+
RETURN_DOUBLE(log2(num));
676+
}
677+
#endif
678+
679+
if (base == 10.0) {
680+
RETURN_DOUBLE(log10(num));
674681
}
675-
if (base == 1) {
682+
683+
if (base == 1.0) {
676684
RETURN_DOUBLE(php_get_nan());
677-
} else {
678-
RETURN_DOUBLE(log(num) / log(base));
679685
}
686+
687+
if (base <= 0.0) {
688+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "base must be greater than 0");
689+
RETURN_FALSE;
690+
}
691+
692+
RETURN_DOUBLE(log(num) / log(base));
680693
}
681694
/* }}} */
682695

0 commit comments

Comments
 (0)