Herbie: Automatically Improving Floating Point Accuracy
herbie.uwplse.org
herbie.uwplse.org
Unfortunately - once you know you have a floating point problem, tracking it down and fixing it may be easy. Not realising it, you won't use these tools and the program will do the wrong thing :)
Once I hooked Herbie up to the Clang Static Analyzer to pull out expressions from code and suggest alternatives. It wasn't a great fit---CSA doesn't model floating point, and it would consider every sub-expression separately as it explored the program. But I think there's merit to the idea.
Also note that the Herbie web demo has some options set that make it fast (to handle load) at the cost of lower accuracy. For example, if you download and install it yourself, you can turn on support for the special numeric functions (like log1p) or increase the number of search iterations done.
Also this is a bit of a special case because it's easy to show that x - x^2 / 2 is within 10^-15 of the true value provided abs(x) is within 10^-6 or so, so it's easy to figure out how good Herbie is doing.
Also if your p-values are approaching machine precision, then maybe p-values aren't the most meaningful metric.
That said, your floating-point code probably didn't come with a numerical analysis to begin with, so how do you know it's better than the replacement? (Well... Herbie does dumb stuff sometimes, so do use with care.)
It isn't something like a compiler plugin that automatically rewrites your code, it just spits out alternative formulations when you give it a math expression...
It also can show you a graph of the error as a function of input value, which is pretty helpful.