Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
57ee21c1
Commit
57ee21c1
authored
Jan 09, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Documentation for the fpectl module, from Lee Busby. (Thanks!)
parent
6843f3de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
0 deletions
+122
-0
Doc/lib/libfpectl.tex
Doc/lib/libfpectl.tex
+122
-0
No files found.
Doc/lib/libfpectl.tex
0 → 100644
View file @
57ee21c1
\section
{
\module
{
fpectl
}
---
Floating point exception control
}
\declaremodule
{
extension
}{
fpectl
}
\platform
{
Unix, Windows
}
\moduleauthor
{
Lee Busby
}{
busby1@llnl.gov
}
\sectionauthor
{
Lee Busby
}{
busby1@llnl.gov
}
\modulesynopsis
{
Provide control for floating point exception handling.
}
Most computers carry out floating point operations
\index
{
IEEE-754
}
in conformance with the so-called IEEE-754 standard.
On any real computer,
some floating point operations produce results that cannot
be expressed as a normal floating point value.
For example, try
\begin{verbatim}
>>> import math
>>> math.exp(1000)
inf
>>> math.exp(1000)/math.exp(1000)
nan
\end{verbatim}
(The example above will work on many platforms.
DEC Alpha may be one exception.)
"Inf" is a special, non-numeric value in IEEE-754 that
stands for "infinity", and "nan" means "not a number."
Note that,
other than the non-numeric results,
nothing special happened when you asked Python
to 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 processing
at the point where the faulty operation was attempted.
The
\module
{
fpectl
}
module
is for use in that situation.
It provides control over floating point
units from several hardware manufacturers,
allowing the user to turn on the generation
of
\constant
{
SIGFPE
}
whenever any of the
IEEE-754 exceptions Division by Zero, Overflow, or
Invalid Operation occurs.
In tandem with a pair of wrapper macros that are inserted
into the C code comprising your python system,
\constant
{
SIGFPE
}
is trapped and converted into the Python
\exception
{
FloatingPointError
}
exception.
The
\module
{
fpectl
}
module defines the following functions and
may raise the given exception:
\begin{funcdesc}
{
turnon
_
sigfpe
}{}
Turn on the generation of
\constant
{
SIGFPE
}
,
and set up an appropriate signal handler.
\end{funcdesc}
\begin{funcdesc}
{
turnoff
_
sigfpe
}{}
Reset default handling of floating point exceptions.
\end{funcdesc}
\begin{excdesc}
{
FloatingPointError
}
After
\function
{
turnon
_
sigfpe()
}
has been executed,
a floating point operation that raises one of the
IEEE-754 exceptions
Division by Zero, Overflow, or Invalid operation
will in turn raise this standard Python exception.
\end{excdesc}
\subsection
{
Example
\label
{
fpectl-example
}}
The following example demonstrates how to start up and test operation of
the
\module
{
fpectl
}
module.
\begin{verbatim}
>>> import fpectl
>>> import fpetest
>>> fpectl.turnon
_
sigfpe()
>>> fpetest.test()
overflow PASS
FloatingPointError: Overflow
div by 0 PASS
FloatingPointError: Division by zero
[ more output from test elided ]
>>> import math
>>> math.exp(1000)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
FloatingPointError: in math
_
1
\end{verbatim}
\subsection
{
Limitations and other considerations
}
Setting up a given processor to trap IEEE-754 floating point
errors currently requires custom code on a per-architecture basis.
You may have to modify
\module
{
fpectl
}
to control your particular hardware.
Conversion of an IEEE-754 exception to a Python exception requires
that the wrapper macros
\code
{
PyFPE
_
START
_
PROTECT
}
and
\code
{
PyFPE
_
END
_
PROTECT
}
be inserted into your code in an appropriate
fashion. Python itself has been modified to support the
\module
{
fpectl
}
module, but many other codes of interest to numerical
analysts have not.
The
\module
{
fpectl
}
module is not thread-safe.
\begin{seealso}
\seetext
{
Some files in the source distribution may be interesting in
learning more about how this module operates.
The include file
\file
{
Include/pyfpe.h
}
discusses the
implementation of this module at some length.
\file
{
Modules/fpetestmodule.c
}
gives several examples of
use.
Many additional examples can be found in
\file
{
Objects/floatobject.c
}
.
}
\end{seealso}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment