xref: /freebsd/lib/msun/man/fegetenv.3 (revision e0c4386e)
1.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd May 8, 2004
26.Dt FEGETENV 3
27.Os
28.Sh NAME
29.Nm fegetenv ,
30.Nm feholdexcept ,
31.Nm fesetenv ,
32.Nm feupdateenv
33.Nd floating-point environment save and restore
34.Sh LIBRARY
35.Lb libm
36.Sh SYNOPSIS
37.In fenv.h
38.Fd "#pragma STDC FENV_ACCESS ON"
39.Ft int
40.Fn fegetenv "fenv_t *envp"
41.Ft int
42.Fn feholdexcept "fenv_t *envp"
43.Ft int
44.Fn fesetenv "const fenv_t *envp"
45.Ft int
46.Fn feupdateenv "const fenv_t *envp"
47.Sh DESCRIPTION
48The floating-point environment includes exception flags and masks, the
49current rounding mode, and other architecture-specific settings.
50However, it does not include the floating-point register file.
51.Pp
52The
53.Fn fegetenv
54function stores the current floating-point environment in the object
55pointed to by
56.Fa envp ,
57whereas
58.Fn feholdexcept
59saves the current environment, then clears all exception flags
60and masks all floating-point exceptions.
61.Pp
62The
63.Fn fesetenv
64function restores a previously saved environment.
65The
66.Fn feupdateenv
67function restores a saved environment as well, but it also
68raises any exceptions that were set in the environment it
69replaces.
70.Pp
71The
72.Fn feholdexcept
73function is often used with
74.Fn feupdateenv
75or
76.Fn fesetenv
77to suppress spurious exceptions that occur as a result of
78intermediate computations.
79An example in
80.Xr fenv 3
81demonstrates how to do this.
82.Sh RETURN VALUES
83The
84.Fn fegetenv ,
85.Fn feholdexcept ,
86.Fn fesetenv ,
87and
88.Fn feupdateenv
89functions return 0 if they succeed, and non-zero otherwise.
90.Sh SEE ALSO
91.Xr feclearexcept 3 ,
92.Xr fenv 3 ,
93.Xr feraiseexcept 3 ,
94.Xr fesetenv 3 ,
95.Xr fetestexcept 3 ,
96.Xr fpgetmask 3 ,
97.Xr fpgetprec 3 ,
98.Xr fpsetmask 3 ,
99.Xr fpsetprec 3
100.Sh STANDARDS
101The
102.Fn fegetenv ,
103.Fn feholdexcept ,
104.Fn fesetenv ,
105and
106.Fn feupdateenv
107functions conform to
108.St -isoC-99 .
109.Sh HISTORY
110These routines first appeared in
111.Fx 5.3 .
112