1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
2 | <html>
|
---|
3 | <!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | (The work of Trevis Rothwell and Nelson Beebe has been assigned or
|
---|
6 | licensed to the FSF.)
|
---|
7 |
|
---|
8 | Permission is granted to copy, distribute and/or modify this document
|
---|
9 | under the terms of the GNU Free Documentation License, Version 1.3 or
|
---|
10 | any later version published by the Free Software Foundation; with the
|
---|
11 | Invariant Sections being "GNU General Public License," with the
|
---|
12 | Front-Cover Texts being "A GNU Manual," and with the Back-Cover
|
---|
13 | Texts as in (a) below. A copy of the license is included in the
|
---|
14 | section entitled "GNU Free Documentation License."
|
---|
15 |
|
---|
16 | (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
|
---|
17 | modify this GNU manual. Buying copies from the FSF supports it in
|
---|
18 | developing GNU and promoting software freedom." -->
|
---|
19 | <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
|
---|
20 | <head>
|
---|
21 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
---|
22 | <title>Special Float Values (GNU C Language Manual)</title>
|
---|
23 |
|
---|
24 | <meta name="description" content="Special Float Values (GNU C Language Manual)">
|
---|
25 | <meta name="keywords" content="Special Float Values (GNU C Language Manual)">
|
---|
26 | <meta name="resource-type" content="document">
|
---|
27 | <meta name="distribution" content="global">
|
---|
28 | <meta name="Generator" content="makeinfo">
|
---|
29 | <link href="index.html" rel="start" title="Top">
|
---|
30 | <link href="Symbol-Index.html" rel="index" title="Symbol Index">
|
---|
31 | <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
---|
32 | <link href="Floating-Point-in-Depth.html" rel="up" title="Floating Point in Depth">
|
---|
33 | <link href="Invalid-Optimizations.html" rel="next" title="Invalid Optimizations">
|
---|
34 | <link href="Floating-Type-Specs.html" rel="prev" title="Floating Type Specs">
|
---|
35 | <style type="text/css">
|
---|
36 | <!--
|
---|
37 | a.summary-letter {text-decoration: none}
|
---|
38 | blockquote.indentedblock {margin-right: 0em}
|
---|
39 | div.display {margin-left: 3.2em}
|
---|
40 | div.example {margin-left: 3.2em}
|
---|
41 | div.lisp {margin-left: 3.2em}
|
---|
42 | kbd {font-style: oblique}
|
---|
43 | pre.display {font-family: inherit}
|
---|
44 | pre.format {font-family: inherit}
|
---|
45 | pre.menu-comment {font-family: serif}
|
---|
46 | pre.menu-preformatted {font-family: serif}
|
---|
47 | span.nolinebreak {white-space: nowrap}
|
---|
48 | span.roman {font-family: initial; font-weight: normal}
|
---|
49 | span.sansserif {font-family: sans-serif; font-weight: normal}
|
---|
50 | ul.no-bullet {list-style: none}
|
---|
51 | -->
|
---|
52 | </style>
|
---|
53 |
|
---|
54 |
|
---|
55 | </head>
|
---|
56 |
|
---|
57 | <body lang="en">
|
---|
58 | <span id="Special-Float-Values"></span><div class="header">
|
---|
59 | <p>
|
---|
60 | Next: <a href="Invalid-Optimizations.html" accesskey="n" rel="next">Invalid Optimizations</a>, Previous: <a href="Floating-Type-Specs.html" accesskey="p" rel="prev">Floating Type Specs</a>, Up: <a href="Floating-Point-in-Depth.html" accesskey="u" rel="up">Floating Point in Depth</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
61 | </div>
|
---|
62 | <hr>
|
---|
63 | <span id="Special-Floating_002dPoint-Values"></span><h3 class="section">28.3 Special Floating-Point Values</h3>
|
---|
64 | <span id="index-special-floating_002dpoint-values"></span>
|
---|
65 | <span id="index-floating_002dpoint-values_002c-special"></span>
|
---|
66 |
|
---|
67 | <p>IEEE floating point provides for special values that are not ordinary
|
---|
68 | numbers.
|
---|
69 | </p>
|
---|
70 | <dl compact="compact">
|
---|
71 | <dt>infinities</dt>
|
---|
72 | <dd><p><code>+Infinity</code> and <code>-Infinity</code> are two different infinite
|
---|
73 | values, one positive and one negative. These result from
|
---|
74 | operations such as <code>1 / 0</code>, <code>Infinity + Infinity</code>,
|
---|
75 | <code>Infinity * Infinity</code>, and <code>Infinity + <var>finite</var></code>, and also
|
---|
76 | from a result that is finite, but larger than the most positive possible
|
---|
77 | value or smaller than the most negative possible value.
|
---|
78 | </p>
|
---|
79 | <p>See <a href="Handling-Infinity.html">Handling Infinity</a>, for more about working with infinities.
|
---|
80 | </p>
|
---|
81 | </dd>
|
---|
82 | <dt>NaNs (not a number)</dt>
|
---|
83 | <dd><span id="index-QNaN"></span>
|
---|
84 | <span id="index-SNaN"></span>
|
---|
85 | <p>There are two special values, called Not-a-Number (NaN): a quiet
|
---|
86 | NaN (QNaN), and a signaling NaN (SNaN).
|
---|
87 | </p>
|
---|
88 | <p>A QNaN is produced by operations for which the value is undefined
|
---|
89 | in real arithmetic, such as <code>0 / 0</code>, <code>sqrt (-1)</code>,
|
---|
90 | <code>Infinity - Infinity</code>, and any basic operation in which an
|
---|
91 | operand is a QNaN.
|
---|
92 | </p>
|
---|
93 | <p>The signaling NaN is intended for initializing
|
---|
94 | otherwise-unassigned storage, and the goal is that unlike a
|
---|
95 | QNaN, an SNaN <em>does</em> cause an interrupt that can be caught
|
---|
96 | by a software handler, diagnosed, and reported. In practice,
|
---|
97 | little use has been made of signaling NaNs, because the most
|
---|
98 | common CPUs in desktop and portable computers fail to implement
|
---|
99 | the full IEEE 754 Standard, and supply only one kind of NaN, the
|
---|
100 | quiet one. Also, programming-language standards have taken
|
---|
101 | decades to catch up to the IEEE 754 standard, and implementations
|
---|
102 | of those language standards make an additional delay before
|
---|
103 | programmers become willing to use these features.
|
---|
104 | </p>
|
---|
105 | <p>To enable support for signaling NaNs, use the GCC command-line option
|
---|
106 | <samp>-fsignaling-nans</samp>, but this is an experimental feature and may
|
---|
107 | not work as expected in every situation.
|
---|
108 | </p>
|
---|
109 | <p>A NaN has a sign bit, but its value means nothing.
|
---|
110 | </p>
|
---|
111 | <p>See <a href="Handling-NaN.html">Handling NaN</a>, for more about working with NaNs.
|
---|
112 | </p>
|
---|
113 | </dd>
|
---|
114 | <dt>subnormal numbers</dt>
|
---|
115 | <dd><span id="index-subnormal-numbers"></span>
|
---|
116 | <span id="index-underflow_002c-floating"></span>
|
---|
117 | <span id="index-floating-underflow"></span>
|
---|
118 | <span id="subnormal-numbers"></span><p>It can happen that a computed floating-point value is too small to
|
---|
119 | represent, such as when two tiny numbers are multiplied. The result
|
---|
120 | is then said to <em>underflow</em>. The traditional behavior before
|
---|
121 | the IEEE 754 Standard was to use zero as the result, and possibly to report
|
---|
122 | the underflow in some sort of program output.
|
---|
123 | </p>
|
---|
124 | <p>The IEEE 754 Standard is vague about whether rounding happens
|
---|
125 | before detection of floating underflow and overflow, or after, and CPU
|
---|
126 | designers may choose either.
|
---|
127 | </p>
|
---|
128 | <p>However, the Standard does something unusual compared to earlier
|
---|
129 | designs, and that is that when the result is smaller than the
|
---|
130 | smallest <em>normalized</em> representable value (i.e., one in
|
---|
131 | which the leading significand bit is <code>1</code>), the normalization
|
---|
132 | requirement is relaxed, leading zero bits are permitted, and
|
---|
133 | precision is gradually lost until there are no more bits in the
|
---|
134 | significand. That phenomenon is called <em>gradual underflow</em>,
|
---|
135 | and it serves important numerical purposes, although it does
|
---|
136 | reduce the precision of the final result. Some floating-point
|
---|
137 | designs allow you to choose at compile time, or even at
|
---|
138 | run time, whether underflows are gradual, or are flushed abruptly
|
---|
139 | to zero. Numbers that have entered the region of gradual
|
---|
140 | underflow are called <em>subnormal</em>.
|
---|
141 | </p>
|
---|
142 | <p>You can use the library functions <code>fesetround</code> and
|
---|
143 | <code>fegetround</code> to set and get the rounding mode. Rounding modes
|
---|
144 | are defined (if supported by the platform) in <code>fenv.h</code> as:
|
---|
145 | <code>FE_UPWARD</code> to round toward positive infinity; <code>FE_DOWNWARD</code>
|
---|
146 | to round toward negative infinity; <code>FE_TOWARDZERO</code> to round
|
---|
147 | toward zero; and <code>FE_TONEAREST</code> to round to the nearest
|
---|
148 | representable value, the default mode. It is best to use
|
---|
149 | <code>FE_TONEAREST</code> except when there is a special need for some other
|
---|
150 | mode.
|
---|
151 | </p></dd>
|
---|
152 | </dl>
|
---|
153 |
|
---|
154 | <hr>
|
---|
155 | <div class="header">
|
---|
156 | <p>
|
---|
157 | Next: <a href="Invalid-Optimizations.html" accesskey="n" rel="next">Invalid Optimizations</a>, Previous: <a href="Floating-Type-Specs.html" accesskey="p" rel="prev">Floating Type Specs</a>, Up: <a href="Floating-Point-in-Depth.html" accesskey="u" rel="up">Floating Point in Depth</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
158 | </div>
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 | </body>
|
---|
163 | </html>
|
---|