Error in sum!
- Node.js Version: 7.10.0
- OS: Windows (64-bit)
- Scope (install, code, runtime, meta, other?):
- Module (and version) (if relevant):
Good morning to the Devs (Brazilian time)!
Bem, gostaria apenas de registrar um erro que eu acidentalmente encontrei com uma soma feita nos terminais de acordo com a impressão anexada, eu testei a soma com vários números decimais, porém o erro acaba sendo ocasionando com os decimais .37 e .38!
Thank you for the excellent work done to NodeJs!
Hello JohnsonMauro, Nothing fundamentally wrong with Node.js; what you have observed is typical with any floating-point arithmetic (and a multitude of other programming languages). Your calculations may be expressed as [float] + [int], but are in practice is converted into [float] + [float] to maintain the precision of your operand.... Except that also creates the scope for imprecision at the very extreme (least significant) bits of what can be represented and accurately maintained in the mantissa, hence you observe discrepancies in the 37th/38th decimal digits.
@shellberg Ahhh, okay, thanks for letting me know!
expressed as [float] + [int], but are […] converted into [float] + [float]
Since this thread is a prominent reference for future learners: Do you mean the conversion for parsing it as a Number type, or do we nowadays have actual integers in standard JS? (not asm.js)
People wondering about the precision: JS Numbers are 64 bit, so if you're from C++, read "[double]" instead of "[float]". ;-)
While we're at it, have a look at Number.MAX_SAFE_INTEGER because 1e99 === (1e99 + 1).
Hi all,
Since there's an agreement that this is "Floating Point Arithmetic" issue and is not node specific, I'm going to close this issue.
@JohnsonMauro Feel free to reopen if you find anything that is a direct node issue.