[Python-ideas] Way to check for floating point "closeness"?

Andrew Barnert abarnert at yahoo.com
Thu Jan 15 03:27:43 CET 2015

On Jan 14, 2015, at 18:13, Ron Adam <ron3200 at gmail.com> wrote:

> By using objects we can do a bit more.  I seem to recall coming across measurement objects some place.  They keep a bit more context with them.

You can use an interval class to represent your measurements with error bars, in which case many problems either go away, or become too obvious to ignore.

In particular, for simple cases at least, you get error analysis for free, and you can just check whether the final interval includes the expected value (or overlaps the expected interval, if there are error bars on the expected result too).

However, finding an interval math library that handles all of the mathematical operations you want for a particular application may not be easy. You might have to ctypes or wrap up a C or C++ library instead. (I'm just guessing, but I suspect more people have written wrappers for such libs to work with numpy/scipy than with native Python scalars.)

More information about the Python-ideas mailing list