[PATCH] Proposed modification to log() in ext/standard/math.c
| From: | Pollita | Date: | Sun, 10 Nov 2002 22:20:28 +0000 |
| Subject: | [PATCH] Proposed modification to log() in ext/standard/math.c | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-90735@lists.php.net to get a copy of this message | ||
I would like to offer the attached minor patch (relative to php-4.2.3) to
ext/standard/math.c to extend the functionality of log() to support
arbitrary bases.
The patch would extend:
float log(float number)
to:
float log(float number[,float base])
With no base parameter specified it would function as before returning the
logarithm with respect to base e. Specifying a base would allow it to
return a logarithm in any other positive base.
For Example:
print log(32,2); // Would output "5"
print log(81,3); // Would output "4"
while:
print log(M_E); // Would still output 1 as normal
I was told on Freenode/#OPN that this was the place to submit suggested
patches.
524,526c524,527 < zval **num; < < if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { --- > zval **num,**Zbase; > double base; > double denom=1.0; > if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || zend_get_parameters_ex(2, &num, &Zbase) == FAILURE) { 528a530,538 > if (ZEND_NUM_ARGS() > 1) { > convert_to_double_ex(Zbase); > base = Z_DVAL_PP(Zbase); > if (base > 0.0) denom = log(base); > else { > php_error(E_WARNING,"base parameter of log() must be greater than 0"); > RETURN_FALSE; > } > } 530c540 < Z_DVAL_P(return_value) = log(Z_DVAL_PP(num)); --- > Z_DVAL_P(return_value) = log(Z_DVAL_PP(num))/denom;
524,526c524,527 < zval **num; < < if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { --- > zval **num,**Zbase; > double base; > double denom=1.0; > if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || zend_get_parameters_ex(2, &num, &Zbase) == FAILURE) { 528a530,538 > if (ZEND_NUM_ARGS() > 1) { > convert_to_double_ex(Zbase); > base = Z_DVAL_PP(Zbase); > if (base > 0.0) denom = log(base); > else { > php_error(E_WARNING,"base parameter of log() must be greater than 0"); > RETURN_FALSE; > } > } 530c540 < Z_DVAL_P(return_value) = log(Z_DVAL_PP(num)); --- > Z_DVAL_P(return_value) = log(Z_DVAL_PP(num))/denom;