Live data from Hacker News

Floating point visually explained (2017)

fabiensanglard.net

51–58 of 58 posts

Re: Floating point visually explained (2017)

#51
post #19

Why is everyone complaining about people finding floats hard? Sure, scientific notation is easy to grasp, but you can't honestly tell me that it's trivial AFTER you consider rounding modes, subnormals, etc. Maybe if hardware had infinite precision like the real numbers nobody would be complaining ;) One thing I dislike in discussions about floats is this incessant focus on the binary representation. The representatio…

>"Sure it matters if you are a hardware guy, or need to work with serialized floats, or some NaN-boxing trickery"

Might you or someone else elaborate on what "NaN-boxing trickery" is and why such "trickery" is needed?

Re: Floating point visually explained (2017)

#52
post #19

Why is everyone complaining about people finding floats hard? Sure, scientific notation is easy to grasp, but you can't honestly tell me that it's trivial AFTER you consider rounding modes, subnormals, etc. Maybe if hardware had infinite precision like the real numbers nobody would be complaining ;) One thing I dislike in discussions about floats is this incessant focus on the binary representation. The representatio…

>"Sure it matters if you are a hardware guy, or need to work with serialized floats, or some NaN-boxing trickery" Might you or someone else elaborate on what "NaN-boxing trickery" is and why such "trickery" is needed?

There are 13 bits that are unused in the NaN representation, so you can put data in there without impeding your ability to represent every floating point value.

For example, if you are designing a scripting language interpreter, you can make every value a floating point number and use some of the NaNs to represent pointers, booleans, etc.

See also http://wingolog.org/archives/2011/05/18/value-representation...

Re: Floating point visually explained (2017)

#53

Earlier quoted context omitted.

Python 3.9.5 >>> 0.1.hex() '0x1.999999999999ap-4' >>> 0.2.hex() '0x1.999999999999ap-3' >>> (0.1 + 0.2).hex() '0x1.3333333333334p-2' >>> 0.3.hex() '0x1.3333333333333p-2'

But they are repeating. So, by definition, they are not exactly representable in a (binary) floating point system. Again, that’s why 0.1 + 0.2 is not 0.3 in binary floating point.

These are not "repeating". This is showing the exact binary representation of the nearest double precision value in each case.

Re: Floating point visually explained (2017)

#54
post #7

Earlier quoted context omitted.

His approach works well for me. I don't retain arbitrary facts. At least part of this is a fear that if I don't properly understand its dynamics I will misapply it, better to discard it. The windowing explanation shows me a path from the intent of the designer through to the implementation (the algorithm). Now I can retain that knowledge.

> I don't retain arbitrary facts. I still fail to understand what is arbitrary in scientific notation. The designers almost certainly didn't think in terms of windows when creating the data types, they probably thought about the mantissa and exponent the way it's usually explained, and maybe about information density (entropy per bit) when comparing with other possibilities. Anyway, if it helps, great. Different expl…

> I still fail to understand what is arbitrary in scientific notation

I used the word arbitrary, but did not say that scientific notation was arbitrary.

I will try to explain another way. The equation is an assertion. For me, it does not plainly follow from the underlying problem. Once the author has introduced the windowing approach, the equation follows easily for me.

> almost certainly [..] they probably [..] Different explanations are always welcome. But this one is post-fact.

By your own words, it is not clear that it is. It is clear that you doubt that the author of the system was thinking in terms of windows and buckets.

Re: Floating point visually explained (2017)

#55
post #32

I was kinda hoping for a visualization of which numbers exists in floating point. While I always new about 0.1 + 0.2 -> 0.30000000000000004 it was still kind of an epiphany realizing that floating point numbers don’t so much have rounding errors as they are simply discreet numbers. You can move from one float to the next, which is a meaningfull operation on discreet numbers like integers, but not continuous numbers l…

> You can move from one float to the next, which is a meaningfull operation on discreet numbers like integers, but not continuous numbers like rational and irrational numbers. What do you mean by continuous? Obviously if you take a number line and remove either the rational or irrational numbers, you will end up with infinitely many holes. The thing that makes floating point numbers unique is that, for any given repr…

> What do you mean by continuous?

I meant continuous in the “mathematical sense”. But maybe continuous is actually statistical term, and dense is the correct mathematical term.

Re: Floating point visually explained (2017)

#56

I was kinda hoping for a visualization of which numbers exists in floating point. While I always new about 0.1 + 0.2 -> 0.30000000000000004 it was still kind of an epiphany realizing that floating point numbers don’t so much have rounding errors as they are simply discreet numbers. You can move from one float to the next, which is a meaningfull operation on discreet numbers like integers, but not continuous numbers l…

I dunno, I feel it better to consider floats to not be a single discrete number but an interval.

Re: Floating point visually explained (2017)

#57
post #14

Earlier quoted context omitted.

Some DSP chips had hardware for fixed point. I think it's a shame that C never added support for fixed point.

There was a draft and GCC supports it in stdfix.h. The downside is that the types have limited integer range since they're tailored for DSP applications where values are kept scaled between +/-1.0.

But the stdfix does not take advantage of SIMD style acceleration right?

Re: Floating point visually explained (2017)

#58
post #13

Earlier quoted context omitted.

But wouldn't it be sweet to have SIMD acceleration for fixed point? Or is that something you can do with integers and SIMD today? Say 4x4 matrix multiplication?

your add is just an integer add. your multiply is a mul_hi, 2 shifts, 1 add and 1 mul.

I know some of those words, but still I'm curious as to why OpenGL has not explored fixed for 3D graphics?
Post reply on HN