News for hackers. Stuff that matters.
Re:Why does 0.1 and 0.2 = 0.30000000000000004? by Kon-Peki on Wednesday February 08, 2023 @03:00PM (#34714001)
> If you design software that works with money amounts, always use fixed point decimals. Don't use floats, it's just wrong!

Don’t write with such certainty! Decimal math is great advice for many/most situations, but what if you have a LOT of numbers and not a lot of time? That big number crunching GPU is not available if you take this approach.

Numerical Methods was the most difficult CS course I took in university and also the one I did the worst in. And of course it was an elective, or else they wouldn’t have graduated many people at all. If you’re doing a lot of number crunching stuff, maybe you should ask people that know how to number crunch to design your system so it has the smallest errors :)

PS - I’m not the person for that job!

Re:Why does 0.1 and 0.2 = 0.30000000000000004? by t8sr on Wednesday February 08, 2023 @03:15PM (#34714272)
I am almost completely certain that neither Google Sheets, nor Excel use that "big number crunching GPU" for anything float-related.

Just getting the data to the GPU for a compute shader to run on it would take longer than just doing on the CPU in almost every case.

Re:Why does 0.1 and 0.2 = 0.30000000000000004? by bruce511 on Thursday February 09, 2023 @12:56AM (#34720255)
I'm not sure if the parent poster meant GPU or CPU. While yeah GPU has good floating point math, you probably don't use that for things like excel.

On the other hand the CPU has floating point math too, and floating point math is MUCH faster than decimal math.

So his point holds if you replace GPU with CPU, but his use of GPU is likely inaccurate.

Re:Why does 0.1 and 0.2 = 0.30000000000000004? by t8sr on Thursday February 09, 2023 @04:32AM (#34721610)
Ah, yeah. The performance of modern FPUs really kills, and it's changing a lot of the assumptions I used to have about performance.

Anecdote: In state of the art physics code, it's common to use integers for coordinates [1]. Recently, I was working on a BSc. toy project, and I used ints for coordinates as is common. With both ints and floats it's important to be careful around functions like `tan` that go to infinity, but of course floats are more forgiving, so I prototyped some of the code using doubles.

I ended up comparing performance and it wasn't even funny. Double precision arithmetic was anywhere between 3x (where a good int algorithm is known) all the way to 100x faster (if the int algorithm is cordic, for example) than integers.

1: Springel 2013 p. 1-82 https://wwwmpa.mpa-garching.mpg.de/gadget4/gadget4-code-pape...

Re:Why does 0.1 and 0.2 = 0.30000000000000004? by albrewer on Thursday February 09, 2023 @11:44AM (#34726795)
> you probably don't use that for things like excel

I'm not sure when I read it, but long ago I read some kind of AMA from a MS engineer working on Excel saying that his greatest achievement was working on the team that made the Excel's DAG solver trivially parallelizable. In the same thread, he mentioned that offloading to the GPU was being looked into. I guess it never came to fruition.

Re:Why does 0.1 and 0.2 = 0.30000000000000004? by Kon-Peki on Thursday February 09, 2023 @12:00PM (#34727089)
> use of GPU is likely inaccurate.

The number 1 supercomputer in the world has 8 million GPU cores (or is it 8 million GPUs? Execution Units?) and 600k CPU cores.

They are doing floating point math on GPUs. Numerical analysis [1] is used to create the best accuracy possible. This is something that has been done for thousands of years, basically since math has had problems with no "exact" solution.

[1] https://en.wikipedia.org/wiki/Numerical_analysis

Re:Why does 0.1 and 0.2 = 0.30000000000000004? by int_19h on Wednesday February 08, 2023 @05:38PM (#34716560)
We should be optimizing for correctness over performance by default, though. People who need binary floating point for perf reasons should already know the tradeoffs.
Re:Why does 0.1 and 0.2 = 0.30000000000000004? by Karellen on Thursday February 09, 2023 @06:49AM (#34722577)
I remember reading on a forum many years ago where one person was rationalising performance over correctness, someone replied that if their code didn't have to be correct they could get the answer in clock 1 cycle with zero memory usage. :-)