Live data from Hacker News

9999999999999999.0 – 9999999999999998.0

geocar.sdf1.org

21–30 of 274 posts

Re: 9999999999999999.0 – 9999999999999998.0

#25
post #9
post #3

2 with 64 bit floats, 0 with 32 bit floats.

I could understand 0, but how does it get 2?

FP numbers are (roughly) stored in the form m×2^e (m = mantissa, e = exponent). When numbers can't be represented exactly, m is rounded. My guess is that these numbers end up being encoded as 4999999999999999×2 and 4999999999999999.5×2, where the latter is rounded up to 5000000000000000×2.

Re: 9999999999999999.0 – 9999999999999998.0

#28
This is particularly sucky to solve in C and C++ because you don't get arbitrary precision literals.

    #include 
    #include 
    #include 

    using fl50 = boost::multiprecision::cpp_dec_float_50;

    int main() {
        auto a = boost::lexical_cast("9999999999999999.7");
        auto b = boost::lexical_cast("9999999999999998.5");
        std::cout 
works

    int main() {
        fl50 a = 9999999999999999.7;
        fl50 b = 9999999999999998.5;
        std::cout 
doesn't, even if you change fl50 out for a quad precision binary float type.

Re: 9999999999999999.0 – 9999999999999998.0

#29
post #15

A useful website for these that I ran across recently: https://float.exposed/ For example, entering 9999999999999999.0 into "double" gives https://float.exposed/0x4341c37937e08000 and entering 9999999999999998.0 gives https://float.exposed/0x4341c37937e07fff My wishlist for such a page would contain two additional features: 1. Allow entering expressions like "a OP b == c", so that one can enter "0.1 + 0.2 == 0.3" or…

[deleted]

Re: 9999999999999999.0 – 9999999999999998.0

#30

Are there any mainstream languages that consider a decimal number to be a primitive type? I feel like floating point numbers are far less meaningful in every day programs. Even 2d graphics would be easier with decimal numbers. Unless you're using numbers that scale from very small to very large, like 3d games or scientific calculations, you don't actually want to use floating point.

[deleted]
Post reply on HN