[Python-Dev] Revamping Python's Numeric Model
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Tue, 7 Nov 2000 01:49:34 +0100
> Is there some API for it in C?
In C99, you have access to the floating-point environment:
#include <fenv.h>
/* ... */
{
#pragma STDC FENV_ACCESS ON
int set_excepts;
feclearexcept(FE_INEXACT | FE_OVERFLOW);
// maybe raise exceptions
set_excepts = fetestexcept(FE_INEXACT | FE_OVERFLOW);
if (set_excepts & FE_INEXACT) f();
if (set_excepts & FE_OVERFLOW) g();
/* ... */
}
It defines the following symbolic exception constants:
FE_DIVBYZERO
FE_INEXACT
FE_INVALID
FE_OVERFLOW
FE_UNDERFLOW
Few compilers support that, though.
Regards,
Martin