Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / module-fpectl.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="module-atexit.html" />
13<link rel="prev" href="module-weakref.html" />
14<link rel="parent" href="python.html" />
15<link rel="next" href="fpectl-example.html" />
16<meta name='aesop' content='information' />
17<title>3.4 fpectl -- Floating point exception control</title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="3.3.3 Weak References in"
25 href="weakref-extension.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="3. Python Runtime Services"
28 href="python.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="3.4.1 Example"
31 href="fpectl-example.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="weakref-extension.html">3.3.3 Weak References in</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="fpectl-example.html">3.4.1 Example</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION005400000000000000000">
563.4 <tt class="module">fpectl</tt> --
57 Floating point exception control</A>
58</H1>
59
60<P>
61<A NAME="module-fpectl"></A>
62<p class="availability">Availability: <span
63 class="platform">Unix</span>.</p>
64
65<P>
66Most computers carry out floating point operations<a id='l2h-434' xml:id='l2h-434'></a>
67in conformance with the so-called IEEE-754 standard.
68On any real computer,
69some floating point operations produce results that cannot
70be expressed as a normal floating point value.
71For example, try
72
73<P>
74<div class="verbatim"><pre>
75&gt;&gt;&gt; import math
76&gt;&gt;&gt; math.exp(1000)
77inf
78&gt;&gt;&gt; math.exp(1000) / math.exp(1000)
79nan
80</pre></div>
81
82<P>
83(The example above will work on many platforms.
84DEC Alpha may be one exception.)
85"Inf" is a special, non-numeric value in IEEE-754 that
86stands for "infinity", and "nan" means "not a number."
87Note that,
88other than the non-numeric results,
89nothing special happened when you asked Python
90to carry out those calculations.
91That is in fact the default behaviour prescribed in the IEEE-754 standard,
92and if it works for you,
93stop reading now.
94
95<P>
96In some circumstances,
97it would be better to raise an exception and stop processing
98at the point where the faulty operation was attempted.
99The <tt class="module">fpectl</tt> module
100is for use in that situation.
101It provides control over floating point
102units from several hardware manufacturers,
103allowing the user to turn on the generation
104of <tt class="constant">SIGFPE</tt> whenever any of the
105IEEE-754 exceptions Division by Zero, Overflow, or
106Invalid Operation occurs.
107In tandem with a pair of wrapper macros that are inserted
108into the C code comprising your python system,
109<tt class="constant">SIGFPE</tt> is trapped and converted into the Python
110<tt class="exception">FloatingPointError</tt> exception.
111
112<P>
113The <tt class="module">fpectl</tt> module defines the following functions and
114may raise the given exception:
115
116<P>
117<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
118 <td><nobr><b><tt id='l2h-431' xml:id='l2h-431' class="function">turnon_sigfpe</tt></b>(</nobr></td>
119 <td><var></var>)</td></tr></table></dt>
120<dd>
121Turn on the generation of <tt class="constant">SIGFPE</tt>,
122and set up an appropriate signal handler.
123</dl>
124
125<P>
126<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
127 <td><nobr><b><tt id='l2h-432' xml:id='l2h-432' class="function">turnoff_sigfpe</tt></b>(</nobr></td>
128 <td><var></var>)</td></tr></table></dt>
129<dd>
130Reset default handling of floating point exceptions.
131</dl>
132
133<P>
134<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-433' xml:id='l2h-433' class="exception">FloatingPointError</tt></b></dt>
135<dd>
136After <tt class="function">turnon_sigfpe()</tt> has been executed,
137a floating point operation that raises one of the
138IEEE-754 exceptions
139Division by Zero, Overflow, or Invalid operation
140will in turn raise this standard Python exception.
141</dd></dl>
142
143<P>
144
145<p><br /></p><hr class='online-navigation' />
146<div class='online-navigation'>
147<!--Table of Child-Links-->
148<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
149
150<UL CLASS="ChildLinks">
151<LI><A href="fpectl-example.html">3.4.1 Example</a>
152<LI><A href="node45.html">3.4.2 Limitations and other considerations</a>
153</ul>
154<!--End of Table of Child-Links-->
155</div>
156
157<DIV CLASS="navigation">
158<div class='online-navigation'>
159<p></p><hr />
160<table align="center" width="100%" cellpadding="0" cellspacing="2">
161<tr>
162<td class='online-navigation'><a rel="prev" title="3.3.3 Weak References in"
163 href="weakref-extension.html"><img src='../icons/previous.png'
164 border='0' height='32' alt='Previous Page' width='32' /></A></td>
165<td class='online-navigation'><a rel="parent" title="3. Python Runtime Services"
166 href="python.html"><img src='../icons/up.png'
167 border='0' height='32' alt='Up One Level' width='32' /></A></td>
168<td class='online-navigation'><a rel="next" title="3.4.1 Example"
169 href="fpectl-example.html"><img src='../icons/next.png'
170 border='0' height='32' alt='Next Page' width='32' /></A></td>
171<td align="center" width="100%">Python Library Reference</td>
172<td class='online-navigation'><a rel="contents" title="Table of Contents"
173 href="contents.html"><img src='../icons/contents.png'
174 border='0' height='32' alt='Contents' width='32' /></A></td>
175<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
176 border='0' height='32' alt='Module Index' width='32' /></a></td>
177<td class='online-navigation'><a rel="index" title="Index"
178 href="genindex.html"><img src='../icons/index.png'
179 border='0' height='32' alt='Index' width='32' /></A></td>
180</tr></table>
181<div class='online-navigation'>
182<b class="navlabel">Previous:</b>
183<a class="sectref" rel="prev" href="weakref-extension.html">3.3.3 Weak References in</A>
184<b class="navlabel">Up:</b>
185<a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A>
186<b class="navlabel">Next:</b>
187<a class="sectref" rel="next" href="fpectl-example.html">3.4.1 Example</A>
188</div>
189</div>
190<hr />
191<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
192</DIV>
193<!--End of Navigation Panel-->
194<ADDRESS>
195See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
196</ADDRESS>
197</BODY>
198</HTML>