Acknowledged

Bug in Simulator 7.2.1 with Float vs Long comparisons

In the following:

    var l = 1L;
    var f = 1.0f;
    System.println(f==l); // false in 7.2.1, true in 7.2.0 and earlier
    System.println(l==f); // false in 7.2.1, true in 7.2.0 and earlier
    System.println(1.0f==1L); // false in 7.2.1 with optimization off, true with optimization on

Essentially, when the 7.2.1 simulator evaluates 1.0f==1L it returns false. All previous simulators return true.

Note that the optimizer also thinks the result is true.

I've not tried on a device yet, but from past experiments I'm pretty sure that all the watches I've used report true.

If this is something that's going to change, or that devices are inconsistent about, the type checker should issue a warning for long vs float comparisons, and the optimizer shouldn't optimize constant comparisons (especially not to the wrong value!). But my guess is that this is just a bug in the simulator.

Parents
  • Sorry, in the previous comparison I should've said "the int is implicitly converted to a double."

    My point stands though. The same would've happened for a literal float and int comparison.

Comment
  • Sorry, in the previous comparison I should've said "the int is implicitly converted to a double."

    My point stands though. The same would've happened for a literal float and int comparison.

Children
No Data