Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Strange bug with #negative #42

@jubianchi

Description

@jubianchi

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 - 2 makes both results identical,
  • 2 + 2 / 2560.4 + - 3 makes both results identical,
  • 2 + 2 / 2560.3 + - 2 makes both results identical,
  • 2 + 2 / 2560.4 + - - 2 makes both results identical,
  • 2 + 2 / 2560.4 + - + 2 makes results different,
  • ...

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions