Merge commit 'dc97a43d4a70c8773a619f11b95b07a787f6f5b7' into merges
[unleashed.git] / share / man / man3head / fenv.h.3head
blob8a4a3b4f16ec68a25fde4ba94cf928b96c4a2283
1 '\" te
2 .\" Copyright (c) 2001, The IEEE and The Open Group. All Rights Reserved. Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
4 .\" http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
6 .\"  This notice shall appear on any product containing this material.
7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
10 .TH FENV.H 3HEAD "Dec 15, 2003"
11 .SH NAME
12 fenv.h, fenv \- floating-point environment
13 .SH SYNOPSIS
14 .LP
15 .nf
16 #include <\fBfenv.h\fR>
17 .fi
19 .SH DESCRIPTION
20 .sp
21 .LP
22 The <\fBfenv.h\fR> header defines the following data types through
23 \fBtypedef\fR:
24 .sp
25 .ne 2
26 .na
27 \fB\fBfenv_t\fR\fR
28 .ad
29 .RS 13n
30 Represents the entire floating-point environment. The floating-point
31 environment refers collectively to any floating-point status flags and control
32 modes supported by the implementation.
33 .RE
35 .sp
36 .ne 2
37 .na
38 \fB\fBfexcept_t\fR\fR
39 .ad
40 .RS 13n
41 Represents the floating-point status flags collectively, including any status
42 the implementation associates with the flags. A floating-point status flag is a
43 system variable whose value is set (but never cleared) when a floating-point
44 exception is raised, which occurs as a side effect of exceptional
45 floating-point arithmetic to provide auxiliary information. A floating-point
46 control mode is a system variable whose value can be set by the user to affect
47 the subsequent behavior of floating-point arithmetic.
48 .RE
50 .sp
51 .LP
52 The <\fBfenv.h\fR> header defines the following constants if and only if the
53 implementation supports the floating-point exception by means of the
54 floating-point functions \fBfeclearexcept()\fR, \fBfegetexceptflag()\fR,
55 \fBferaiseexcept()\fR, \fBfesetexceptflag()\fR,  and \fBfetestexcept()\fR. Each
56 expands to an integer constant expression with values such that
57 bitwise-inclusive ORs of all combinations of the constants result in distinct
58 values.
59 .sp
60 .in +2
61 .nf
62 FE_DIVBYZERO
63 FE_INEXACT
64 FE_INVALID
65 FE_OVERFLOW
66 FE_UNDERFLOW
67 .fi
68 .in -2
70 .sp
71 .LP
72 The <\fBfenv.h\fR> header defines the following constant, which is simply the
73 bitwise-inclusive OR of all floating-point exception constants defined above:
74 .sp
75 .in +2
76 .nf
77 FE_ALL_EXCEPT
78 .fi
79 .in -2
81 .sp
82 .LP
83 The <\fBfenv.h\fR> header defines the following constants. Each expands to an
84 integer constant expression whose values are distinct non-negative values.
85 .sp
86 .in +2
87 .nf
88 FE_DOWNWARD
89 FE_TONEAREST
90 FE_TOWARDZERO
91 FE_UPWARD
92 .fi
93 .in -2
95 .sp
96 .LP
97 The <\fBfenv.h\fR> header defines the following constant, which represents the
98 default floating-point environment (that is, the one installed at program
99 startup) and has type pointer to const-qualified \fBfenv_t\fR. It can be used
100 as an argument to the functions within the <\fBfenv.h\fR> header that manage
101 the floating-point environment.
103 .in +2
105 FE_DFL_ENV
107 .in -2
111 The \fBFENV_ACCESS\fR pragma provides a means to inform the implementation when
112 an application might access the floating-point environment to test
113 floating-point status flags or run under non-default floating-point control
114 modes. The pragma occurs either outside external declarations or preceding all
115 explicit declarations and statements inside a compound statement. When outside
116 external declarations, the pragma takes effect from its occurrence until
117 another \fBFENV_ACCESS\fR pragma is encountered, or until the end of the
118 translation unit. When inside a compound statement, the pragma takes effect
119 from its occurrence until another \fBFENV_ACCESS\fR pragma is encountered
120 (including within a nested compound statement), or until the end of the
121 compound statement; at the end of a compound statement the state for the pragma
122 is restored to its condition just before the compound statement. If this pragma
123 is used in any other context, the behavior is undefined.
126 If part of an application tests floating-point status flags, sets
127 floating-point control modes, or runs under non-default mode settings, but was
128 translated with the state for the \fBFENV_ ACCESS\fR pragma off, the behavior
129 is undefined. The default state (on or off) for the pragma is
130 implementation-defined. (When execution passes from a part of the application
131 translated with \fBFENV_ACCESS\fR off to a part translated with
132 \fBFENV_ACCESS\fR on, the state of the floating-point status flags is
133 unspecified and the floating-point control modes have their default settings.)
134 .SH USAGE
137 This header is designed to support the floating-point exception status flags
138 and directed-rounding control modes required by the IEC 60559: 1989 standard,
139 and other similar floating-point state information. Also, it is designed to
140 facilitate code portability among all systems.  Certain application programming
141 conventions support the intended model of use for the floating-point
142 environment:
143 .RS +4
145 .ie t \(bu
146 .el o
147 A function call does not alter its caller's floating-point control modes, clear
148 its caller's floating-point status flags, or depend on the state of its
149 caller's floating-point status flags unless the function is so documented.
151 .RS +4
153 .ie t \(bu
154 .el o
155 A function call is assumed to require default floating-point control modes,
156 unless its documentation promises otherwise.
158 .RS +4
160 .ie t \(bu
161 .el o
162 A function call is assumed to have the potential for raising floating-point
163 exceptions, unless its documentation promises otherwise.
167 With these conventions, an application can safely assume default floating-point
168 control modes (or be unaware of them). The responsibilities associated with
169 accessing the floating-point environment fall on the application that does so
170 explicitly.
173 Even though the rounding direction macros might expand to constants
174 corresponding to the values of \fBFLT_ROUNDS\fR, they are not required to do
175 so. For example:
177 .in +2
179 #include <fenv.h>
180 void f(double x)
182     #pragma STDC FENV_ACCESS ON
183     void g(double);
184     void h(double);
185     /* ... */
186     g(x + 1);
187     h(x + 1);
188     /* ... */
191 .in -2
195 If the function \fIg\fR() might depend on status flags set as a side effect of
196 the first \fIx\fR+1, or if the second \fIx\fR+1 might depend on control modes
197 set as a side effect of the call to function \fIg\fR(), then the application
198 must contain an appropriately placed invocation as follows:
200 .in +2
202 #pragma STDC FENV_ACCESS ON
204 .in -2
206 .SH ATTRIBUTES
209 See \fBattributes\fR(5) for descriptions of the following attributes:
214 box;
215 c | c
216 l | l .
217 ATTRIBUTE TYPE  ATTRIBUTE VALUE
219 Interface Stability     Standard
222 .SH SEE ALSO
225 \fBfeclearexcept\fR(3M), \fBfegetenv\fR(3M), \fBfegetexceptflag\fR(3M),
226 \fBfegetround\fR(3M), \fBfeholdexcept\fR(3M), \fBferaiseexcept\fR(3M),
227 \fBfesetenv\fR(3M), \fBfesetexceptflag\fR(3M), \fBfesetround\fR(3M),
228 \fBfetestexcept\fR(3M), \fBfeupdateenv\fR(3M), \fBattributes\fR(5),
229 \fBstandards\fR(5)