Live data from Hacker News

What every computer scientist should know about floating-point arithmetic (1991) [pdf]

itu.dk

21–30 of 55 posts

Re: What every computer scientist should know about floating-point arithmetic (1991) [pdf]

#21
post #9
post #8

Earlier quoted context omitted.

.125 + .375 == .5 You should be using == for floats when they're actually equal. 0.1 just isn't an actual number.

> 0.1 just isn't an actual number. A finitist computer scientists only accepts those numbers as real that can be expressed exactly in finite base-two floating point?

0.1 is of course a real number, but let A \in R the set of actual numbers... (/s)

Re: What every computer scientist should know about floating-point arithmetic (1991) [pdf]

#22
post #20

For anyone turned off by this document and its proofs, I recommend Numerical Methods for Scientists and Engineers (Hamming). Still a math text, but more approachable. The five key ideas from that book, enumerated by the author: (1) the purpose of computing is insight, not numbers (2) study families and relationships of methods, not individual algorithms (3) roundoff error (4) truncation error (5) instability

Can you elaborate a little on what 1 is supposed to mean?

Not the OP, but I suspect it means focus on what questions are being asked first, and even then, look for opportunities to simplify wherever you find them.

So many of us spend so much time getting enamoured with technical solutions to problems that no one cares about.

Re: What every computer scientist should know about floating-point arithmetic (1991) [pdf]

#23
post #20

For anyone turned off by this document and its proofs, I recommend Numerical Methods for Scientists and Engineers (Hamming). Still a math text, but more approachable. The five key ideas from that book, enumerated by the author: (1) the purpose of computing is insight, not numbers (2) study families and relationships of methods, not individual algorithms (3) roundoff error (4) truncation error (5) instability

Can you elaborate a little on what 1 is supposed to mean?

> This motto is often thought to mean that the numbers from a computing machine should be read and used, but there is much more to the motto. The choice of the particular formula, or algorithm, influences not only the computing but also how we are to understand the results when they are obtained. The way the computing progresses, the number of iterations it requires, or the spacing used by a formula, often sheds light on the problem...Thus computing is, or at least should be, intimately bound up with both the source of the problem and the use that is going to be made of the answers-- it is not a step to be taken in isolation from reality

(From "An Essay on Numerical Methods" p 3 of the mentioned text; emphasis authors)

Re: What every computer scientist should know about floating-point arithmetic (1991) [pdf]

#24
post #4

One thing that really did it for me was programming something where you would normally use floats (audio/DSP) on a platform where floats were abysmally slow. This forced me to explore Fixed-Point options which in turn forced me to explore what the differences to floats are.

Fixed point gave rise to the old programmers meme 'if you need floating point you don't understand your problem'. It's of course partially in jest but there is a grain of truth in it as well.

[deleted]

Re: What every computer scientist should know about floating-point arithmetic (1991) [pdf]

#25
post #21
post #9

Earlier quoted context omitted.

> 0.1 just isn't an actual number. A finitist computer scientists only accepts those numbers as real that can be expressed exactly in finite base-two floating point?

0.1 is of course a real number, but let A \in R the set of actual numbers... (/s)

Should be \subset.

Re: What every computer scientist should know about floating-point arithmetic (1991) [pdf]

#26
post #6

> 0.1 + 0.1 + 0.1 == 0.3 False I always tell my students that if they (might) have a float, and are using the `==` operator, they're doing something wrong.

> they (might) have a float, and are using the `==` operator, they're doing something wrong. Storage, retrieval, transmission, and serialization/deserialization systems should be able to transmit and round-trip floats without losing any bits at all.

Floats break the basic expectation of == for round-trip verification, not due to programmer error, but because NaN is non-reflexive by spec. A bit-perfect round-trip can reproduce the exact bit pattern and still fail an equality check. The problem is intrinsic to the type, not the operator.

Re: What every computer scientist should know about floating-point arithmetic (1991) [pdf]

#28
post #21
post #9

Earlier quoted context omitted.

> 0.1 just isn't an actual number. A finitist computer scientists only accepts those numbers as real that can be expressed exactly in finite base-two floating point?

0.1 is of course a real number, but let A \in R the set of actual numbers... (/s)

\infty is an actual number not in R

Re: What every computer scientist should know about floating-point arithmetic (1991) [pdf]

#29
post #21
post #9

Earlier quoted context omitted.

> 0.1 just isn't an actual number. A finitist computer scientists only accepts those numbers as real that can be expressed exactly in finite base-two floating point?

0.1 is of course a real number, but let A \in R the set of actual numbers... (/s)

The funny thing is, according to infinitists real numbers are not real. But I do like the concept of the set of actual numbers.

Re: What every computer scientist should know about floating-point arithmetic (1991) [pdf]

#30
Shared this because I was having fun thinking through floating point numbers the other day.

I worked through what fp6 (e3m2) would look like, doing manual additions and multiplications, showing cases where the operations are non-associative, etc. and then I wanted something more rigorous to read.

For anyone interested in floating point numbers, I highly recommend working through fp6 as an activity! Felt like I truly came away with a much deeper understanding of floats. Anything less than fp6 felt too simple/constrained, and anything more than fp6 felt like too much to write out by hand. For fp6 you can enumerate all 64 possible values on a small sheet of paper.

For anyone not (yet) interested in floating point numbers, I’d still recommend giving it a shot.

Post reply on HN