From 7c36d3350dc2e75c0095788026d385fe7424eca8 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Tue, 17 Sep 2013 09:01:02 +0200 Subject: [PATCH 1/2] use log2 (if possible) and log10 within basic log function to reduce rounding errors --- ext/standard/config.m4 | 2 +- ext/standard/math.c | 23 +++++++++++++++++------ main/php_stdint.h | 4 ++-- 3 files changed, 20 insertions(+), 9 deletions(-) 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)); } /* }}} */ diff --git a/main/php_stdint.h b/main/php_stdint.h index 87edb0fde085a..e5433ab683dcb 100644 --- a/main/php_stdint.h +++ b/main/php_stdint.h @@ -85,7 +85,7 @@ typedef int16 int16_t; # elif SIZEOF_SHORT >= 2 typedef signed short int16_t; # else -# error "No suitable 16bit integer type found" +// # error "No suitable 16bit integer type found" # endif #endif @@ -101,7 +101,7 @@ typedef u_int16_t uint16_t; # elif SIZEOF_SHORT >= 2 typedef unsigned short uint16_t; # else -# error "No suitable 16bit integer type found" +// # error "No suitable 16bit integer type found" # endif #endif From 46deaed75bd291d48c35a38bb224228d52ebb238 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Thu, 19 Sep 2013 21:32:26 +0200 Subject: [PATCH 2/2] reverted changes in main/stdint.h --- main/php_stdint.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/php_stdint.h b/main/php_stdint.h index e5433ab683dcb..87edb0fde085a 100644 --- a/main/php_stdint.h +++ b/main/php_stdint.h @@ -85,7 +85,7 @@ typedef int16 int16_t; # elif SIZEOF_SHORT >= 2 typedef signed short int16_t; # else -// # error "No suitable 16bit integer type found" +# error "No suitable 16bit integer type found" # endif #endif @@ -101,7 +101,7 @@ typedef u_int16_t uint16_t; # elif SIZEOF_SHORT >= 2 typedef unsigned short uint16_t; # else -// # error "No suitable 16bit integer type found" +# error "No suitable 16bit integer type found" # endif #endif