[Python-Dev] PROPOSAL: exposure of values in limits.h and float.h

Trent Mick trentm@activestate.com
Tue, 2 May 2000 16:03:22 -0700


I apologize if I am hitting covered ground. What about a module (called
limits or something like that) that would expose some appropriate #define's
in limits.h and float.h.

For example:

limits.FLT_EPSILON could expose the C DBL_EPSILON
limits.FLT_MAX could expose the C DBL_MAX
limits.INT_MAX could expose the C LONG_MAX (although that particulay name
would cause confusion with the actual C INT_MAX)


- Does this kind of thing already exist somewhere? Maybe in NumPy.

- If we ever (perhaps in Py3K) turn the basic types into classes then these
  could turn into constant attributes of those classes, i.e.:
  f = 3.14159
  f.EPSILON = <as set by C's DBL_EPSILON>

- I thought of these values being useful when I thought of comparing two
  floats for equality. Doing a straight comparison of floats is
  dangerous/wrong but is it not okay to consider two floats reasonably equal
  iff:
  	-EPSILON < float2 - float1 < EPSILON
  Or maybe that should be two or three EPSILONs. It has been a while since
  I've done any numerical analysis stuff.

  I suppose the answer to my question is: "It depends on the situation."
  Could this algorithm for float comparison be a better default than the
  status quo? I know that Mark H. and others have suggested that Python
  should maybe not provide a float comparsion operator at all to beginners.



Trent

--
Trent Mick
trentm@activestate.com