Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / node183.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="prev" href="node182.html" />
13<link rel="parent" href="decimal-notes.html" />
14<link rel="next" href="decimal-threads.html" />
15<meta name='aesop' content='information' />
16<title>5.6.5.2 Special values</title>
17</head>
18<body>
19<DIV CLASS="navigation">
20<div id='top-navigation-panel' xml:id='top-navigation-panel'>
21<table align="center" width="100%" cellpadding="0" cellspacing="2">
22<tr>
23<td class='online-navigation'><a rel="prev" title="5.6.5.1 Mitigating round-off error"
24 href="node182.html"><img src='../icons/previous.png'
25 border='0' height='32' alt='Previous Page' width='32' /></A></td>
26<td class='online-navigation'><a rel="parent" title="5.6.5 Floating Point Notes"
27 href="decimal-notes.html"><img src='../icons/up.png'
28 border='0' height='32' alt='Up One Level' width='32' /></A></td>
29<td class='online-navigation'><a rel="next" title="5.6.6 Working with threads"
30 href="decimal-threads.html"><img src='../icons/next.png'
31 border='0' height='32' alt='Next Page' width='32' /></A></td>
32<td align="center" width="100%">Python Library Reference</td>
33<td class='online-navigation'><a rel="contents" title="Table of Contents"
34 href="contents.html"><img src='../icons/contents.png'
35 border='0' height='32' alt='Contents' width='32' /></A></td>
36<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
37 border='0' height='32' alt='Module Index' width='32' /></a></td>
38<td class='online-navigation'><a rel="index" title="Index"
39 href="genindex.html"><img src='../icons/index.png'
40 border='0' height='32' alt='Index' width='32' /></A></td>
41</tr></table>
42<div class='online-navigation'>
43<b class="navlabel">Previous:</b>
44<a class="sectref" rel="prev" href="node182.html">5.6.5.1 Mitigating round-off error</A>
45<b class="navlabel">Up:</b>
46<a class="sectref" rel="parent" href="decimal-notes.html">5.6.5 Floating Point Notes</A>
47<b class="navlabel">Next:</b>
48<a class="sectref" rel="next" href="decimal-threads.html">5.6.6 Working with threads</A>
49</div>
50<hr /></div>
51</DIV>
52<!--End of Navigation Panel-->
53
54<H3><A NAME="SECTION007652000000000000000">
555.6.5.2 Special values</A>
56</H3>
57
58<P>
59The number system for the <tt class="module">decimal</tt> module provides special
60values including <tt class="constant">NaN</tt>, <tt class="constant">sNaN</tt>, <tt class="constant">-Infinity</tt>,
61<tt class="constant">Infinity</tt>, and two zeroes, <tt class="constant">+0</tt> and <tt class="constant">-0</tt>.
62
63<P>
64Infinities can be constructed directly with: <code>Decimal('Infinity')</code>. Also,
65they can arise from dividing by zero when the <tt class="exception">DivisionByZero</tt>
66signal is not trapped. Likewise, when the <tt class="exception">Overflow</tt> signal is not
67trapped, infinity can result from rounding beyond the limits of the largest
68representable number.
69
70<P>
71The infinities are signed (affine) and can be used in arithmetic operations
72where they get treated as very large, indeterminate numbers. For instance,
73adding a constant to infinity gives another infinite result.
74
75<P>
76Some operations are indeterminate and return <tt class="constant">NaN</tt>, or if the
77<tt class="exception">InvalidOperation</tt> signal is trapped, raise an exception. For
78example, <code>0/0</code> returns <tt class="constant">NaN</tt> which means ``not a number''. This
79variety of <tt class="constant">NaN</tt> is quiet and, once created, will flow through other
80computations always resulting in another <tt class="constant">NaN</tt>. This behavior can be
81useful for a series of computations that occasionally have missing inputs --
82it allows the calculation to proceed while flagging specific results as
83invalid.
84
85<P>
86A variant is <tt class="constant">sNaN</tt> which signals rather than remaining quiet
87after every operation. This is a useful return value when an invalid
88result needs to interrupt a calculation for special handling.
89
90<P>
91The signed zeros can result from calculations that underflow.
92They keep the sign that would have resulted if the calculation had
93been carried out to greater precision. Since their magnitude is
94zero, both positive and negative zeros are treated as equal and their
95sign is informational.
96
97<P>
98In addition to the two signed zeros which are distinct yet equal,
99there are various representations of zero with differing precisions
100yet equivalent in value. This takes a bit of getting used to. For
101an eye accustomed to normalized floating point representations, it
102is not immediately obvious that the following calculation returns
103a value equal to zero:
104
105<P>
106<div class="verbatim"><pre>
107&gt;&gt;&gt; 1 / Decimal('Infinity')
108Decimal("0E-1000000026")
109</pre></div>
110
111<P>
112
113<DIV CLASS="navigation">
114<div class='online-navigation'>
115<p></p><hr />
116<table align="center" width="100%" cellpadding="0" cellspacing="2">
117<tr>
118<td class='online-navigation'><a rel="prev" title="5.6.5.1 Mitigating round-off error"
119 href="node182.html"><img src='../icons/previous.png'
120 border='0' height='32' alt='Previous Page' width='32' /></A></td>
121<td class='online-navigation'><a rel="parent" title="5.6.5 Floating Point Notes"
122 href="decimal-notes.html"><img src='../icons/up.png'
123 border='0' height='32' alt='Up One Level' width='32' /></A></td>
124<td class='online-navigation'><a rel="next" title="5.6.6 Working with threads"
125 href="decimal-threads.html"><img src='../icons/next.png'
126 border='0' height='32' alt='Next Page' width='32' /></A></td>
127<td align="center" width="100%">Python Library Reference</td>
128<td class='online-navigation'><a rel="contents" title="Table of Contents"
129 href="contents.html"><img src='../icons/contents.png'
130 border='0' height='32' alt='Contents' width='32' /></A></td>
131<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
132 border='0' height='32' alt='Module Index' width='32' /></a></td>
133<td class='online-navigation'><a rel="index" title="Index"
134 href="genindex.html"><img src='../icons/index.png'
135 border='0' height='32' alt='Index' width='32' /></A></td>
136</tr></table>
137<div class='online-navigation'>
138<b class="navlabel">Previous:</b>
139<a class="sectref" rel="prev" href="node182.html">5.6.5.1 Mitigating round-off error</A>
140<b class="navlabel">Up:</b>
141<a class="sectref" rel="parent" href="decimal-notes.html">5.6.5 Floating Point Notes</A>
142<b class="navlabel">Next:</b>
143<a class="sectref" rel="next" href="decimal-threads.html">5.6.6 Working with threads</A>
144</div>
145</div>
146<hr />
147<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
148</DIV>
149<!--End of Navigation Panel-->
150<ADDRESS>
151See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
152</ADDRESS>
153</BODY>
154</HTML>