3 ms·
This should be one of the required units of study in Floating Point School. Quick--why would you sort an array of floating point numbers before adding them up?
by wglb 13y ago
This should be one of the required units of study in Floating Point School.
Quick--why would you sort an array of floating point numbers before adding them up? And in which order?
- alanh 13y agoOoh, nice question. Floats are a quantity and a magnitude. Adding two floats requires (at least) the larger of the two magnitudes because larger values are more important than smaller ones. So the smaller float essentially gets converted to a small quantity and a large magnitude. In an extreme case, this small quantity becomes zero. So when adding a very large number and a very small number, the result will be the same as adding zero to the very large number. If you add numbers largest to smallest, then thanks to this, at a certain point you are simply doing $SUM = $SUM + 0 over and over. But if you start with the smallest numbers, they have a chance to add up to a value with a magnitude high enough to survive being added to the largest numbers.
- wglb 13y agoExactly.