]> granicus.if.org Git - php/commitdiff
Improved logarithm of base 2 and 10 of standard math functions
authorMarc Bennewitz <marc-bennewitz@arcor.de>
Mon, 28 Apr 2014 17:58:10 +0000 (19:58 +0200)
committerMarc Bennewitz <marc-bennewitz@arcor.de>
Mon, 28 Apr 2014 17:58:10 +0000 (19:58 +0200)
ext/standard/config.m4
ext/standard/math.c

index c1f5aff7c25b15fab9d19defac65b007d15b709b..e1f9941790bbba76b491901b8aef61d3b34b8f66 100644 (file)
@@ -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
index 72f6d51c6faf109bf0f390a24364662d81cfc1a9..b33b6e28da50ad81968be1fa24583645c045a37c 100644 (file)
@@ -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));
 }
 /* }}} */