• Yepp, it's rounding and bitwise operations, simplest repro is
    🥁

    🥁🥁

    🥁🥁🥁:

    0.99999999999999995 & 1
    

    Results:

    // Firefox and Chromium:
    > 0.99999999999999994&1
    0
    
    > 0.99999999999999995&1
    1
    
    > 0.99999999999999996&1
    1
    
    // Espruino:
    >0.99999999999999994&1
    =0
    
    >0.99999999999999995&1
    =0
    
    // It's ok just a bit higher:
    >0.99999999999999996&1
    =1
    

    Edit: with @Robin's numbers:

    // In browser:
    > var val = 915E6;
    > var newVal = val * Math.pow(2, 19);
    > var newDiv = newVal / 32000000
    > {val, newVal, newDiv}
    {val: 915000000, newVal: 479723520000000, newDiv: 14991360}
    > (newDiv-14991360)*1e9
    0
    // Exactly 0 in browser
    
    // Espruino:
    ...
    >newDiv-14991360
    =-0
    >(newDiv-14991360)*1e9
    =-1.86264514923
    // not exactly 0!
    
About

Avatar for AkosLukacs @AkosLukacs started