diff options
-rw-r--r-- | src/NXP/Classes/Tokenizer.php | 2 | ||||
-rw-r--r-- | tests/MathTest.php | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/NXP/Classes/Tokenizer.php b/src/NXP/Classes/Tokenizer.php index f8056c3..77014b8 100644 --- a/src/NXP/Classes/Tokenizer.php +++ b/src/NXP/Classes/Tokenizer.php @@ -159,7 +159,7 @@ class Tokenizer } // could be in exponent, in which case negative should be added to the numberBuffer if ($this->numberBuffer && $this->numberBuffer[strlen($this->numberBuffer) - 1] == 'e') { - $this->numberBuffer .= '-'; + $this->numberBuffer .= $ch; continue 2; } } diff --git a/tests/MathTest.php b/tests/MathTest.php index d086acb..426e514 100644 --- a/tests/MathTest.php +++ b/tests/MathTest.php @@ -508,6 +508,14 @@ class MathTest extends TestCase $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() { $calculator = new MathExecutor(); |