Reals are much weirder/more interesting than floats, imo.
Floats Are Weird
81–90 of 120 posts
Re: Floats Are Weird
#82Earlier quoted context omitted.
It’s not (or shouldn’t be), it’s simply a result of math, as the article explains in length.
Many libm implementations don't have an accurate `log` or `exp` routine, so there does exist a risk. (Of course, it's also true that many of them also special-case `log(x) ~= x - 1` and `exp(x) ~= x + 1` for small enough `x`.)
Re: Floats Are Weird
#83Re: Floats Are Weird
#84Re money systems: I have found that problems arise no matter whether floats are used or something else: The system can be too exact. My current approach is that I try to guess (or ask) how a customer understands or checks a statement/invoice. The customer usually takes a calculator and enters the rounded numbers they see. I then try to do all programmatic calculations exactly the same way: Operation - round - operati…
I thought "money systems" always worked in whole units of some fraction of your currency, e.g. "millicents" or similar, and shunned floating point arithmetic like the plague. > The system can be too exact Indeed, high precision, low accuracy! Fixed-point arithmetic can be both precise and accurate if everyone agrees on the same system. Maybe we don't, and that's the problem?
Re: Floats Are Weird
#85Then what's the best way to handle these cases? Are there any set of rules we should use while implementing the mathematical equations dealing with limits in floating points.
Other commenters have pointed to tricks that are undoubtedly useful, but the real answer imo is to understand where rounding error will be introduced in your problem, and where it can become catastrophic so that you can use careful alternatives in those cases.
Re: Floats Are Weird
#86Anyway, toying with a slide rule is a fun way of making these things very obvious, because you are essentially working with something like 3-digit floating point. When you find yourself subtracting 1.234 from 1.235, but you know that both the "4" and the "5" are really fuzzy around the edges, it becomes obvious that the resulting 0.001 does not really mean much. Similarly, when you take 1.234e+6 (again with a really fuzzy "4") and add 2, you realize that 1.234002e+6 is not really a sane answer.
Re: Floats Are Weird
#87Earlier quoted context omitted.
That's not what the post says if I understand correctly - the post explains why in certain situations the "noise" disappears, and in other cases it doesn't. See comparison between f and g functions.
I see! yes, the magic is you can cancel the noise by repeating it twice: ``` In [1]: math.exp(1e-15)-1 Out[1]: 1.1102230246251565e-15 In [2]: math.log(math.exp(1e-15)) Out[2]: 1.110223024625156e-15 ``` risky business though, I imagine it's implementation dependent
Re: Floats Are Weird
#88It’s not so much that floats are weird, but that they are not reals. Most of the problems happen due to confusion about this fact. Reals are much weirder/more interesting than floats, imo.
Re: Floats Are Weird
#89It’s not so much that floats are weird, but that they are not reals. Most of the problems happen due to confusion about this fact. Reals are much weirder/more interesting than floats, imo.
the axiomatization of floating point arithmetic is much larger than the axiomatization of real arithmetic, so it is reasonable to describe the former as more complicated.
The reals are stranger than most people realize.
Re: Floats Are Weird
#90we teach students from arithmetic to differential equations assuming they are working with Real Numbers and never really talking about what that means or what a Field is. Then we present computation as something that can easily be done with Real numbers. Which is a lie because we don't even know if Pi plus E is rational or not.
Then we present computers as tools of computation, handwaving away the fact that Computer floating point math is not using real numbers, and is not a Field nor anything even remotely like a Field. Floats are not even closed under basic arithmetic operations. And god help someone who learned Geometry on graph paper then tries to apply it to a computer with Floats because Floats cannot even represent a uniform grid in space, they vary in resolution by definition depending on distance from origin.
So in the end by trying to gloss over the details of how Real Numbers work, and how Computers work, we have actually misrepresented both Real Numbers and Computers to generations of people, for going on 80 years now. And we keep having to have these articles, or "your calculator is wrong" videos go viral every few months/years because people were not taught basic facts about Reals and Computers.