Hacker News new | past | comments | ask | show | jobs | submit login

> The quadratic equation violated the cardinal rule of numerical analysis: avoid subtracting nearly equal numbers. The more similar two numbers are, the more precision you can lose from subtracting them.

Are there other "rules" like this, regarding numerical analysis? I understand this, but I've never thought of articulating it like that.




If you add together many numbers, do it in ascending order, numbers with smallest absolute values first.

Comparing floats is tricky. Use either epsilon, epsilon with relative error or ULP's (all are tricky)


That costs a sort, better to use the Kahan summation formula https://en.wikipedia.org/wiki/Kahan_summation_algorithm


Look at the accuracy comment, it's faster but less accurate than sorting first.


If the numbers happen to be >=0, one could do a little better by merging in Huffman order. In big 'O' the time complexity is the same.


There are surprisingly many situations where the unwary end up violating this cardinal rule. For example: solving a system of linear equations. Mathematically, you can use any pivot, but numerical stability suffers if you don't take the largest possible one. All of this uses to be standard in 1st year engineering classes, so I'm always quite surprised when I see articles like this on HN.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: