maximum Integer value

Posted on
  • When we use a variable to store an Integer, is there a maximum on the Espruino board? The official maximum for Javascript is 2^53, but I don't know if this holds up for the Espruino.

    Furthermore, is there a performance maximum? I would assume that smaller numbers are more efficient since they are easier to represent and can fit in one register. Up to what maximum number would performance be best?

    Finally, I assume that the chars in a String range from 0-255? I looked through the reference, but I could not find any description of how to use Unicode chars so I assume those are not supported?

  • Hi Kim,

    • Number range: Espruino uses 64 bit integers wherever possible (so +/- 2^63), however as soon as you start doing floating point stuff (even 100/50) it'll drop back to doubles, where 2^53 is probably the limit before you lose accuracy.

    • Performance: The overhead of parsing is really much higher than that of maths, so (at least at the moment) you're unlikely to notice a big difference whatever numbers you use. Trying to stick to integer values will probably help though (you can coerce doubles into integers using | - eg. x=x|0.

    • Unicode: yes, characters in Strings are only 8 bits - so if you want to do Unicode you'll have to use UTF-8. Espruino itself is completely unaware though, which could make life tricky.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

maximum Integer value

Posted by Avatar for Kim @Kim

Actions