Merge pull request #92 from ideatic/fix-scientific-notation

fix: broken support for positive exponent numbers
This commit is contained in:
Alex 2022-01-06 12:59:10 +03:00 committed by GitHub
commit 9442a6f471
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -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;
}
}

View file

@ -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();