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;

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to