3 ms·
This is patently false. Floats are not "inaccurate" and are not a "mess". They are well-defined and quite useful in a huge domain of applications.
by reikonomusha 13y ago
This is patently false. Floats are not "inaccurate" and are not a "mess". They are well-defined and quite useful in a huge domain of applications.
- stingraycharles 13y agoSorry, I should've been more clear. They are well defined and useful in a huge domain of applications, especially in those areas where an approximation is perfectly fine. For representing money, however, you need to be very, very careful and be aware of the many subtle bugs that can be introduced when using floats. Also, that something is "well-defined" does not imply that is it not a mess. There are quite a few well-defined standards out there that clearly are a mess.
- reikonomusha 13y agoYou are right. For money, floating point computations are entirely inappropriate, but not because floating point is (supposedly) a "mess", but because floating point sacrifices uniform quantization for an exponential range of representable values. The IEEE-754 standard is not a mess. It is complicated, because it has to be. Extreme care and precision must be taken when talking about mathematical quantities which are neither closed nor associative under the provided operations. I challenge anyone else to make a concrete standard which supports accurate transcendental operations with numbers which range from 0 to 10^300 while remaining simple and easy to understand.
- nolite 13y agodid you not read the parent threads?
- reikonomusha 13y agoYes, I read them. And I am hearing that floats are "inaccurate", "a mess", and so on. I am not advocating their use to represent currency whatsoever, but the reasons are not because of the above, but rather the reason that I described.
- coldtea 13y agoWell, I call 0.3+0.3+0.3 <> 0.9 inaccurate in my book. They might be "well defined" but accurate they are not. In fact the whole point of them is that they are ONLY accurate to some degree.
- reikonomusha 13y agoThat is an accurate calculation, but it is not exact. Moreover, when you do floating point arithmetic, you are not adding the number "0.3" up three times. You are adding an approximation of "0.3" up three times, since 0.3 does not have an exact representation in binary. What you're saying is akin to saying "Well, I call 0.3333 + 0.3333 + 0.3333 = 0.9999 <> 1.0 inaccurate in my book." This is totally accurate, and easier to see because it's in decimal. The point of them is not that they are accurate to some degree. Floating point numbers have a direct correspondence to a real number. The "problem" is that the reverse is not true, so rounding has to occur.
- coldtea 13y ago>That is an accurate calculation, but it is not exact. You know that accurate is a synonym of exact, right? 1. accurate [noun] (of information, measurements, statistics, etc.) correct in all details; exact. >Moreover, when you do floating point arithmetic, you are not adding the number "0.3" up three times. You are adding an approximation of "0.3" up three times, since 0.3 does not have an exact representation in binary. As a CS graduate, I've known that for some decades. But that's at the floating point level, which is beside the point (no pun intented). What the user wants to add is 0.3 -- he could even have entered that verbatim as his input. How it's done is irrelevant to him. What we're saying in this thread is that if that's what you want to do, and you're handling money, FP is not a good represenation. >What you're saying is akin to saying "Well, I call 0.3333 + 0.3333 + 0.3333 = 0.9999 <> 1.0 inaccurate in my book." No, what I'm saying is akin to saying: "I call EXPLICITLY WRITING 0.3+0.3+0.3 and internally getting 0.3333 + 0.3333 + 0.3333 inaccurate in my book".
- bunderbunder 13y agoUsually. But sometimes you get the odd significance loss[1] situation. 1: http://en.wikipedia.org/wiki/Loss_of_significance http://en.wikipedia.org/wiki/Loss_of_significance