Merge pull request #92 from ideatic/fix-scientific-notation
fix: broken support for positive exponent numbers
This commit is contained in:
commit
9442a6f471
2 changed files with 9 additions and 1 deletions
|
@ -159,7 +159,7 @@ class Tokenizer
|
||||||
}
|
}
|
||||||
// could be in exponent, in which case negative should be added to the numberBuffer
|
// could be in exponent, in which case negative should be added to the numberBuffer
|
||||||
if ($this->numberBuffer && $this->numberBuffer[strlen($this->numberBuffer) - 1] == 'e') {
|
if ($this->numberBuffer && $this->numberBuffer[strlen($this->numberBuffer) - 1] == 'e') {
|
||||||
$this->numberBuffer .= '-';
|
$this->numberBuffer .= $ch;
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,6 +508,14 @@ class MathTest extends TestCase
|
||||||
$this->assertEquals(1, $calculator->execute('1-0'));
|
$this->assertEquals(1, $calculator->execute('1-0'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testScientificNotation()
|
||||||
|
{
|
||||||
|
$calculator = new MathExecutor();
|
||||||
|
$this->assertEquals(1.5e9, $calculator->execute('1.5e9'));
|
||||||
|
$this->assertEquals(1.5e-9, $calculator->execute('1.5e-9'));
|
||||||
|
$this->assertEquals(1.5e+9, $calculator->execute('1.5e+9'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetFunctionsReturnsArray()
|
public function testGetFunctionsReturnsArray()
|
||||||
{
|
{
|
||||||
$calculator = new MathExecutor();
|
$calculator = new MathExecutor();
|
||||||
|
|
Loading…
Reference in a new issue