Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
2  lib/evalmath/evalmath.class.php
@@ -212,7 +212,7 @@ function nfx($expr) {
212 212 while(1) { // 1 Infinite Loop ;)
213 213 $op = substr($expr, $index, 1); // get the first character at the current index
214 214 // find out if we're currently at the beginning of a number/variable/function/parenthesis/operand
215   - $ex = preg_match('/^('.self::$namepat.'\(?|\d+(?:\.\d*)?|\.\d+|\()/', substr($expr, $index), $match);
  215 + $ex = preg_match('/^('.self::$namepat.'\(?|\d+(?:\.\d*)?(?:(e[+-]?)\d*)?|\.\d+|\()/', substr($expr, $index), $match);
216 216 //===============
217 217 if ($op == '-' and !$expecting_op) { // is it a negation instead of a minus?
218 218 $stack->push('_'); // put a negation on the stack
18 lib/simpletest/testmathslib.php
@@ -194,6 +194,24 @@ public function test_rounding_function() {
194 194
195 195 }
196 196
  197 + public function test_scientific_notation() {
  198 + $formula = new calc_formula('=10e10');
  199 + $this->assertWithinMargin($formula->evaluate(), 1e11, 1e11*1e-15);
  200 +
  201 + $formula = new calc_formula('=10e-10');
  202 + $this->assertWithinMargin($formula->evaluate(), 1e-9, 1e11*1e-15);
  203 +
  204 + $formula = new calc_formula('=10e+10');
  205 + $this->assertWithinMargin($formula->evaluate(), 1e11, 1e11*1e-15);
  206 +
  207 + $formula = new calc_formula('=10e10*5');
  208 + $this->assertWithinMargin($formula->evaluate(), 5e11, 1e11*1e-15);
  209 +
  210 + $formula = new calc_formula('=10e10^2');
  211 + $this->assertWithinMargin($formula->evaluate(), 1e22, 1e22*1e-15);
  212 +
  213 + }
  214 +
197 215 }
198 216
199 217

0 comments on commit 9085134

Please sign in to comment.
Something went wrong with that request. Please try again.