source: public/doc/gnu-c/Special-Float-Values.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 7.8 KB
Line 
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
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing 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<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.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>
60Next: <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> &nbsp; [<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
68numbers.
69</p>
70<dl compact="compact">
71<dt>infinities</dt>
72<dd><p><code>+Infinity</code> and <code>-Infinity</code> are two different infinite
73values, one positive and one negative. These result from
74operations such as <code>1 / 0</code>, <code>Infinity + Infinity</code>,
75<code>Infinity * Infinity</code>, and <code>Infinity + <var>finite</var></code>, and also
76from a result that is finite, but larger than the most positive possible
77value 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
86NaN (QNaN), and a signaling NaN (SNaN).
87</p>
88<p>A QNaN is produced by operations for which the value is undefined
89in real arithmetic, such as <code>0 / 0</code>, <code>sqrt (-1)</code>,
90<code>Infinity - Infinity</code>, and any basic operation in which an
91operand is a QNaN.
92</p>
93<p>The signaling NaN is intended for initializing
94otherwise-unassigned storage, and the goal is that unlike a
95QNaN, an SNaN <em>does</em> cause an interrupt that can be caught
96by a software handler, diagnosed, and reported. In practice,
97little use has been made of signaling NaNs, because the most
98common CPUs in desktop and portable computers fail to implement
99the full IEEE 754 Standard, and supply only one kind of NaN, the
100quiet one. Also, programming-language standards have taken
101decades to catch up to the IEEE 754 standard, and implementations
102of those language standards make an additional delay before
103programmers 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
107not 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
119represent, such as when two tiny numbers are multiplied. The result
120is then said to <em>underflow</em>. The traditional behavior before
121the IEEE 754 Standard was to use zero as the result, and possibly to report
122the underflow in some sort of program output.
123</p>
124<p>The IEEE 754 Standard is vague about whether rounding happens
125before detection of floating underflow and overflow, or after, and CPU
126designers may choose either.
127</p>
128<p>However, the Standard does something unusual compared to earlier
129designs, and that is that when the result is smaller than the
130smallest <em>normalized</em> representable value (i.e., one in
131which the leading significand bit is <code>1</code>), the normalization
132requirement is relaxed, leading zero bits are permitted, and
133precision is gradually lost until there are no more bits in the
134significand. That phenomenon is called <em>gradual underflow</em>,
135and it serves important numerical purposes, although it does
136reduce the precision of the final result. Some floating-point
137designs allow you to choose at compile time, or even at
138run time, whether underflows are gradual, or are flushed abruptly
139to zero. Numbers that have entered the region of gradual
140underflow 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
144are 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>
146to round toward negative infinity; <code>FE_TOWARDZERO</code> to round
147toward zero; and <code>FE_TONEAREST</code> to round to the nearest
148representable value, the default mode. It is best to use
149<code>FE_TONEAREST</code> except when there is a special need for some other
150mode.
151</p></dd>
152</dl>
153
154<hr>
155<div class="header">
156<p>
157Next: <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> &nbsp; [<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>
Note: See TracBrowser for help on using the repository browser.