Acknowledged
over 1 year ago

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
  • > But my guess is that this is just a bug in the simulator.

    I really hope so

    > 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

    But ofc that wouldn't help for apps which have already been deployed or apps which don't use type checking, or in situations where the type isn't certain. And if it was a warning, devs would feel free to ignore it.

Comment
  • > But my guess is that this is just a bug in the simulator.

    I really hope so

    > 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

    But ofc that wouldn't help for apps which have already been deployed or apps which don't use type checking, or in situations where the type isn't certain. And if it was a warning, devs would feel free to ignore it.

Children
No Data