• The point is -IMO - there is something wrong with floating point calculation. The bit-mask mismatch is a result of the floating point error.

    The result of calculation 915E6 * Math.pow(2,19) in Espruino is not 479723520000000, it's 479723519999999.9375.

    To demonstrate it, ran this in

    • Espruino 'Linux' build on my laptop
    • DS-D6 (nRF52832, just sitting in a box, BLE console is really convenient :) )
    • Browser console
    • node v8.11.2
    • F# interactive (.Net, to test on completely different platform)

    Results are identical in non-Espruino environments:

    > 915E6 * Math.pow(2,19)
    // The result in Espruino: 479723519999999.9375  
    // The result in browser / node / F#: 479723520000000
    

    Oh, btw just bit-shifting indeed wraps around in browser & node:

    > 915E6<<10
    657129472
    > 915E6<<11
    1314258944
    > 915E6<<12
    -1666449408
    > 915E6<<13
    962068480
    > 915E6<<14
    1924136960
    > 915E6<<15
    -446693376
    > 915E6<<16
    -893386752
    > 915E6<<17
    -1786773504
    > 915E6<<18
    721420288
    > 915E6<<19
    1442840576
    
About

Avatar for AkosLukacs @AkosLukacs started