[PYTHON MATRIX-SIG] floating point handling

Guido van Rossum guido@CNRI.Reston.VA.US
Fri, 03 Nov 1995 10:08:39 -0500

>    If you insist on having "Inf" for infinity and "NaN" for 1/0, all you
>    probably need to do is hack the floatobject.c module a wee bit, to
>    include representations for them and to return them in appropriate
> Indeed I don't think this is much work, having looked at the float
> implementation quite a bit before writing the complex module. But
> obviously there must be a way to enable or disable floating point
> exceptions (I thing everyone agrees they are useful). I am not quite
> sure what the appropriate way to do that would be - a variable in the
> sys module would be nice, but probably expensive to check after each
> float operation. A function with a boolean argument that sets a C
> variable might be better. Or maybe there is a better way that I just
> can't think of... The same flag could then be used in the complex and
> matrix modules.

Hmm...  Globals that affect the behavior of low-level objects are
rarely a good idea.  For instance, some non-compute-intensive module
may be using floats and expecting exceptions -- it will break if it is
used in your program that turns off exceptions...

How about introducing a new type, say ieeefloat, with the desired
behavior?  Its casting behavior could easily be designed to force
mixed-mode arithmetic (between standard and ieee floats) to be done in
ieee mode.

--Guido van Rossum <guido@CNRI.Reston.VA.US>
URL: <http://www.python.org/~guido/>

MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org