This repository was archived by the owner on Sep 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Strange bug with #negative #42
Copy link
Copy link
Open
Description
Here is the expression I use : $expr = '2 + 2 / 2560.4 + - 2';
With PHP, I get:
<?php
var_dump((float) eval('return ' . $expr . ';')); // float(0.00078112794875818)With Math, I get:
<?php
use Hoa\Compiler;
use Hoa\File;
use Hoa\Math\Visitor\Arithmetic;
$compiler = Compiler\Llk\Llk::load(new File\Read('hoa://Library/Math/Arithmetic.pp'));
$visitor = new Arithmetic();
$dump = new Compiler\Visitor\Dump();
$ast = $compiler->parse($expr);
echo $dump->visit($ast);
var_dump((float) $visitor->visit($ast)); // float(0.00078112794875795)Here is the produced AST:
> #addition
> > token(number, 2)
> > #addition
> > > #division
> > > > token(number, 2)
> > > > token(number, 2560.4)
> > > #negative
> > > > token(number, 2)
Changing the expression to:
2 + 2 / 2560.4 - 2makes both results identical,2 + 2 / 2560.4 + - 3makes both results identical,2 + 2 / 2560.3 + - 2makes both results identical,2 + 2 / 2560.4 + - - 2makes both results identical,2 + 2 / 2560.4 + - + 2makes results different,- ...
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.