Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[php] Problem with Float/Int equality #4260

Closed
Simn opened this issue May 28, 2015 · 4 comments
Closed

[php] Problem with Float/Int equality #4260

Simn opened this issue May 28, 2015 · 4 comments
Assignees
Labels
platform-php Everything related to PHP
Milestone

Comments

@Simn
Copy link
Member

Simn commented May 28, 2015

class Main {
    static function main() {
        var f:Float = 0;
        var i:Float = 0.0;
        trace(i == f); // false
    }
}

genphp tries to be smart by determining that the operand types are equal and thus being able to use ===, which evaluates to false. Note that it could not use == either because that would give incorrect equality results when null is involved. This is somewhat problematic because it would mean we have to go a slow equality route for every numeric equality check.

We can try to detect the original assignment of 0 to Float and convert it at run-time, but I have no idea if PHP is going to play along.

@Simn
Copy link
Member Author

Simn commented Jun 4, 2015

This is kind of related to old neko issue #1282.

@Simn Simn added the platform-php Everything related to PHP label Jun 4, 2015
@Simn Simn self-assigned this Jun 4, 2015
@Simn Simn modified the milestone: 3.4 Feb 23, 2016
@Simn Simn modified the milestone: 3.4 Mar 16, 2016
@Simn Simn assigned RealyUniqueName and unassigned Simn Dec 7, 2016
@RealyUniqueName
Copy link
Member

I went a slow route for float vs float comparison. One should not check floats for equality anyway.

@back2dos
Copy link
Member

I propose to do the following instead:

  1. Any integer constant top down inferred to be a float should be generated as float, i.e. the above var f:Float = 0 should generate $f = 0.0.
  2. Any int expression unified with float should be wrapped in floatval.

@RealyUniqueName
Copy link
Member

Such approach will not cover floats which come from dynamics (json, external php code, native functions). While current fix works for any case with the least possible overhead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-php Everything related to PHP
Projects
None yet
Development

No branches or pull requests

3 participants