Availability:Unix.
Note:Thefpectl module is not built by default, and its usage is discouraged and may be dangerous except in the hands of experts. See also the section26.13.2 on limitations for more details.
Most computers carry out floating point operationsin conformance with the so-called IEEE-754 standard.On any real computer,some floating point operations produce results that cannotbe expressed as a normal floating point value.For example, try
>>> import math>>> math.exp(1000)inf>>> math.exp(1000) / math.exp(1000)nan
(The example above will work on many platforms.DEC Alpha may be one exception.)"Inf" is a special, non-numeric value in IEEE-754 thatstands for "infinity", and "nan" means "not a number."Note that,other than the non-numeric results,nothing special happened when you asked Pythonto carry out those calculations.That is in fact the default behaviour prescribed in the IEEE-754 standard,and if it works for you,stop reading now.
In some circumstances,it would be better to raise an exception and stop processingat the point where the faulty operation was attempted.Thefpectl moduleis for use in that situation.It provides control over floating pointunits from several hardware manufacturers,allowing the user to turn on the generationofSIGFPE whenever any of theIEEE-754 exceptions Division by Zero, Overflow, orInvalid Operation occurs.In tandem with a pair of wrapper macros that are insertedinto the C code comprising your python system,SIGFPE is trapped and converted into the PythonFloatingPointError exception.
Thefpectl module defines the following functions andmay raise the given exception:
| ) |
| ) |