Apologies... I've made a new .patch file relative to revision 1.93 of
math.c in the CVS tree with modifications per instructions in
CODING_STANDARDS.  Hope this meets with approval.


> On Sun, 10 Nov 2002, Pollita wrote:
>
>> 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.
>
> Please provide a unified diff (diff -u) against the latest CVS version.
> Also, please stick to the coding standards as described in the
> CODING_STANDARDS file.
>
> regards,
> Derick
>
> --
>
> ---------------------------------------------------------------------------
>  Derick Rethans
> http://derickrethans.nl/  JDI Media Solutions
> --------------[ if you hold a unix shell to your ear, do you hear the c?
> ]-


--- math.c      Sun Nov 10 14:34:19 2002
+++ math-smg.c  Sun Nov 10 14:39:39 2002
@@ -525,13 +525,27 @@
 
 PHP_FUNCTION(log)
 {
-       zval **num;
+       zval **num,**Zbase;
+       double base;
+       double denom=1.0;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
+       if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || zend_get_parameters_ex(2, 
+&num, &Zbase) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+       /* If second parameter "base" is specified, use it, otherwise accept e */
+        if (ZEND_NUM_ARGS() > 1) {
+                convert_to_double_ex(Zbase);
+                base = Z_DVAL_PP(Zbase);
+                if (base > 0.0) denom = log(base);
+                        else    {
+                                       /* A base of <= 0 is non-sensical */
+                                        php_error(E_WARNING,"base parameter of log() 
+must be greater than 0");
+                                        RETURN_FALSE;
+                                }
+        }
+
        convert_to_double_ex(num);
-       Z_DVAL_P(return_value) = log(Z_DVAL_PP(num));
+       Z_DVAL_P(return_value) = log(Z_DVAL_PP(num)) / denom;
        Z_TYPE_P(return_value) = IS_DOUBLE;
 }
 



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

Reply via email to