r47203 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47202‎ | r47203 | r47204 >
Date:23:49, 12 February 2009
Author:werdna
Status:deferred
Tags:
Comment:
Per Simetrical on code review, fix confused implementation of log (just convert to doubles and use the inaccurate floating-point math for now), and move initialisation to doExpression, instead of haveBC.
Modified paths:
  • /trunk/extensions/ParserFunctions/Expr.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserFunctions/Expr.php
@@ -157,8 +157,6 @@
158158
159159 if ($haveBC === null) {
160160 $haveBC = extension_loaded( 'bcmath' );
161 - if ($haveBC) // Set to precision of 14.
162 - bcscale(16);
163161 }
164162
165163 return $haveBC;
@@ -178,6 +176,11 @@
179177 # Unescape inequality operators
180178 $expr = strtr( $expr, array( '&lt;' => '<', '&gt;' => '>',
181179 '&minus;' => '-', '−' => '-' ) );
 180+
 181+ ## initialise BC
 182+ if ( $this->haveBC() ) {
 183+ bcscale(16);
 184+ }
182185
183186 $p = 0;
184187 $end = strlen( $expr );
@@ -582,10 +585,7 @@
583586 if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]);
584587 $arg = array_pop( $stack );
585588 if ( $arg <= 0 ) throw new ExprError('invalid_argument_ln', $this->names[$op]);
586 - if ($haveBC) // ln(x) = 1^(1/e)
587 - $stack[] = bcpow( $arg, bcdiv( 1, exp(1) ) );
588 - else
589 - $stack[] = log($arg);
 589+ $stack[] = log( doubleval($arg) );
590590 break;
591591 case EXPR_ABS:
592592 if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]);

Status & tagging log