Hacker News new | ask | show | jobs
by roessland 893 days ago
Here's a great introduction to floating-point numbers: https://tobydriscoll.net/fnc-julia/intro/floating-point.html

The next representable number after 9999999999999998.0 is 1.0e16. 9999999999999999.0 is not exactly representable in IEEE 754 floats, and will be rounded up or down.

The difference between 0.0 and 2.0 in the table is likely due to different rounding modes. I'm curious how different languages end up with different rounding modes. Is that possible to configure?

    julia> 9999999999999999.0 - 9999999999999998.0
    2.0

    julia> -9.999999999999999 + 9.999999999999998
    0.0
1 comments

It's not different rounding modes, but different floating point formats. Google is doing something very weird that is also base 10 related. Not sure about TCL.
TCL does for quite some years now use real integers (unbounded size) and floats (float8) whenever possible. By the way, the article does not specify versions of languages, so:

    $ tclsh
    % puts $tcl_version
    8.6
    % expr "9999999999999999.0-9999999999999998.0"
    2.0