Hacker News new | ask | show | jobs
by enriquto 1256 days ago
> not having exact integers

What do you mean? Floating-point arithmetic is, by design, exact for small integers. The result of adding 2.0 to 3.0 is exactly 5.0. This is one of the few cases where it is perfectly legitimate to compare floats for equality.

In fact, using 64-bit doubles to represent ints you get way more ints than using plain 32-bit ints. Thus, choosing doubles to represent integers makes perfect sense (unless you worry about wasting a bit of memory and performance).

1 comments

Having something work most of the time but break without warning - at least by writing to a log that an overflow has happened - goes against a lot of SWE best practices AFAICT. Imagine debugging that without knowing it can happen.

Does JS at least write ".0" at the end when converting a number to a string? Or switch to scientific notation for large numbers?