Live data from Hacker News

9999999999999999.0 – 9999999999999998.0

geocar.sdf1.org

51–60 of 274 posts

Re: 9999999999999999.0 – 9999999999999998.0

#51
post #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 c…

> Even user-defined literals in C++11 and later don't let you express custom floating point expressions

Note that in your code sample you're not actually using user-defined literals (https://en.cppreference.com/w/cpp/language/user_literal). This works (based on on your earlier code sample and adding user-defined literals):

    #include 
    #include 
    #include 
    using fl50 = boost::multiprecision::cpp_dec_float_50;
    fl50 operator"" _w(const char* s) { return boost::lexical_cast(s); }
    int main() {
        fl50 a = 9999999999999999.7_w;
        fl50 b = 9999999999999998.5_w;
        std::cout 

Re: 9999999999999999.0 – 9999999999999998.0

#52
post #39

I don't understand all the crap that IEEE 754 gets. I appreciate that it may be surprising that 0.1 + 0.2 != 0.3 at first, or that many people are not educated about floating point, but I don't understand the people who "understand" floating point and continue to criticize it for the 0.1 + 0.2 "problem." The fact is that IEEE 754 is an exceptionally good way to approximate the reals in computers with a minimum number…

Yeah, the limitations of FP are well-known to anyone who does much numerical work.

Floating point numbers are the optimal minimum message length method of representing reals with an improper Jeffery's prior distribution. A Jeffery's prior is a prior that is invariant under reparameterization, which is a mandatory property for approximating the reals.

In this case, it is where Prob(log(|x|)) is proportional to a constant.

Thus, we aren't going to ever do better than floats if we are programming on physical computers that exist in this universe. There is a reason why all numerical code uses them. Best to learn their limitations if you are going to use them, otherwise use arbitrary precision.

Re: 9999999999999999.0 – 9999999999999998.0

#54
post #46

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.

Julia has built in rationals (as do a few other languages). I'm not aware of any language (other than Wolfram) that defaults to storing something like 0.1 as 1/10 - i.e. uses the decimal constant notation for rationals, rather than having some secondary syntax or library.

In Common Lisp it's even standardized. Arithmetic is too important to be left to wrong CPU intrinsics.

Re: 9999999999999999.0 – 9999999999999998.0

#55
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…

This is awesome, I tried to read and understand the 754 float spec before, and I didn't really get it.

Try playing around with half precision, it makes things a lot easier to understand.

Re: 9999999999999999.0 – 9999999999999998.0

#56
post #39

I don't understand all the crap that IEEE 754 gets. I appreciate that it may be surprising that 0.1 + 0.2 != 0.3 at first, or that many people are not educated about floating point, but I don't understand the people who "understand" floating point and continue to criticize it for the 0.1 + 0.2 "problem." The fact is that IEEE 754 is an exceptionally good way to approximate the reals in computers with a minimum number…

People get upset that floating point can’t represent all infinite number of real numbers exactly - I can’t understand how they think that’s going to be possible in a finite 64 bits.

Re: 9999999999999999.0 – 9999999999999998.0

#57
post #51
post #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 c…

> Even user-defined literals in C++11 and later don't let you express custom floating point expressions Note that in your code sample you're not actually using user-defined literals ( https://en.cppreference.com/w/cpp/language/user_literal ). This works (based on on your earlier code sample and adding user-defined literals): #include #include #include using fl50 = boost::multiprecision::cpp_dec_float_50; fl50 operato…

Thanks, it's nice to be wrong! For some reason I had it in my head that you couldn't get the token as a char const* for floating point expressions...

Re: 9999999999999999.0 – 9999999999999998.0

#58

DAE mind blown by imprecision in float arith? Edit: Down-Voters go ahead and explain the LIE that is computer accuracy in the face of the linked demonstration. Computers, can't trust em.

You're probably being downvoted for posting like you're on some other site, moreso than your sentiment that this is just a simple CS 101 thing that people ought to know. Thing is, a lot of people don't take CS courses, and have to learn this as they go along. More importantly, the naive cases all seem to work fine - it's only when you get to increasing precision / scales that you notice the cracks in the facade, and…

Exact real arithmetic is an open research problem (and slow, as well). Arbitrary precision has its own can of worms and is slow, too.

Re: 9999999999999999.0 – 9999999999999998.0

#60
post #37

What is the "right answer"? Is the article claiming that such languages don't respect IEEE-754, or that IEEE-754 is shit? If you want arbitrary precision, use an arbitrary precision datatype. If you use fixed precision, you'll need to know how those floats work. Pointless article, imho.

The point is to illustrate a simple fact that most of us know- but maybe some don't. https://m.xkcd.com/1053/

I was one of those people today! This intrigued me enough to learn more about IEEE 754.

Thank you for the relevant xkcd!

Post reply on HN