-
Notifications
You must be signed in to change notification settings - Fork 91
Description
TinyJS seems to treat integers differently from other numbers?
enno@erdbaer:~/src/tiny-js@master$ ./Script
> Interactive mode... Type quit(); to exit, or print(...); to print something, or dump() to dump the symbol table!
print(5/2);
> 2
print(5.0/2);
> 2.500000
print(123 === 123.0);
> 0
This doesn't match the behavior of other Javascript implementations, or indeed the wording at https://www.w3schools.com/js/js_numbers.asp:
Unlike many other programming languages, JavaScript does not define different types of numbers, like integers, short, long, floating-point etc.
JavaScript numbers are always stored as double precision floating point numbers, following the international IEEE 754 standard.
And the standard explicitly says:
ECMAScript does not perform integer division. The operands and result of all division operations are double-precision floating-point numbers.
Is this intentional? Is there a way to make TinyJS behave like the standard? Perhaps a compile-time option could be added?