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!
@AkosLukacs started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Yepp, it's rounding and bitwise operations, simplest repro is
🥁
🥁🥁
🥁🥁🥁:
Results:
Edit: with @Robin's numbers: