floating point control in extensions

Tim Peters tim.one at comcast.net
Sun Jul 13 14:04:00 EDT 2003


[Robin Becker]
> Is there a preferred way to intercept floating point exceptions in
> python extensions? I assume one should be careful to restore any
> existing error handler.

Python itself assumes that no-stop mode is in effect (the IEEE-754 mandated
default:  all FPU traps are disabled).

> Does python have a standard mechanism for setting up fpu control
> words etc?

See Modules/fpectlmodule.c.  Note that the 2.3 NEWS file says:

> - The fpectl module is not built by default; it's dangerous or
>   useless except in the hands of experts.

fpectlmodule.c is a cross-platform nightmare, it often doesn't work even on
the platforms someone once tried to make it work on (the magic incantations
required sometimes even vary across specific releases of specific compilers
on specific platforms), and it appeared that nobody used it anyway.  If
compiler vendors eventually implement the optional IEEE-754 API defined by
C99, that would allow a much saner approach.

iow-for-now-you're-on-your-own-ly y'rs  - tim






More information about the Python-list mailing list