i386 removal, part 43/x: Remove/change i386 specific info in manual pages.
[dragonfly.git] / share / man / man3 / fpgetround.3
1 .\" Copyright (c) 1993 Andrew Moore, Talke Studio
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 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)fpgetround.3        1.0 (Berkeley) 9/23/93
29 .\" $FreeBSD: src/share/man/man3/fpgetround.3,v 1.20 2013/04/12 00:37:30 svnexp Exp $
30 .\"
31 .Dd July 14, 2013
32 .Dt FPGETROUND 3
33 .Os
34 .Sh NAME
35 .Nm fpgetround ,
36 .Nm fpsetround ,
37 .Nm fpsetprec ,
38 .Nm fpgetprec ,
39 .Nm fpgetmask ,
40 .Nm fpsetmask ,
41 .Nm fpgetsticky ,
42 .Nm fpresetsticky
43 .Nd IEEE floating point interface
44 .Sh LIBRARY
45 .Lb libc
46 .Sh SYNOPSIS
47 .In ieeefp.h
48 .Bd -literal
49 typedef enum {
50         FP_RN,          /* round to nearest */
51         FP_RM,          /* round down to minus infinity */
52         FP_RP,          /* round up to plus infinity */
53         FP_RZ           /* truncate */
54 } fp_rnd_t;
55 .Ed
56 .Ft fp_rnd_t
57 .Fn fpgetround void
58 .Ft fp_rnd_t
59 .Fn fpsetround "fp_rnd_t direction"
60 .Bd -literal
61 typedef enum {
62         FP_PS,          /* 24 bit (single-precision) */
63         FP_PRS,         /* reserved */
64         FP_PD,          /* 53 bit (double-precision) */
65         FP_PE           /* 64 bit (extended-precision) */
66 } fp_prec_t;
67 .Ed
68 .Ft fp_prec_t
69 .Fn fpgetprec void
70 .Ft fp_prec_t
71 .Fn fpsetprec "fp_prec_t precision"
72 .Bd -literal
73 #define fp_except_t     int
74 #define FP_X_INV        0x01    /* invalid operation */
75 #define FP_X_DNML       0x02    /* denormal */
76 #define FP_X_DZ         0x04    /* zero divide */
77 #define FP_X_OFL        0x08    /* overflow */
78 #define FP_X_UFL        0x10    /* underflow */
79 #define FP_X_IMP        0x20    /* (im)precision */
80 #define FP_X_STK        0x40    /* stack fault */
81 .Ed
82 .Ft fp_except_t
83 .Fn fpgetmask void
84 .Ft fp_except_t
85 .Fn fpsetmask "fp_except_t mask"
86 .Ft fp_except_t
87 .Fn fpgetsticky void
88 .Ft fp_except_t
89 .Fn fpresetsticky "fp_except_t sticky"
90 .Sh DESCRIPTION
91 The routines described herein are deprecated.
92 New code should use the functionality provided by
93 .Xr fenv 3 .
94 .Pp
95 When a floating point exception is detected, the exception sticky flag is
96 set and the exception mask is tested.
97 If the mask is set, then a trap occurs.
98 These routines allow both setting the floating point exception
99 masks, and resetting the exception sticky flags after an exception is
100 detected.
101 In addition, they allow setting the floating point rounding mode
102 and precision.
103 .Pp
104 The
105 .Fn fpgetround
106 function
107 returns the current floating point rounding mode.
108 .Pp
109 The
110 .Fn fpsetround
111 function
112 sets the floating point rounding mode and returns
113 the previous mode.
114 .Pp
115 The
116 .Fn fpgetprec
117 function
118 returns the current floating point precision.
119 .Pp
120 The
121 .Fn fpsetprec
122 function
123 sets the floating point precision and returns
124 the previous precision.
125 .Pp
126 The
127 .Fn fpgetmask
128 function
129 returns the current floating point exception masks.
130 .Pp
131 The
132 .Fn fpsetmask
133 function
134 sets the floating point exception masks and returns the
135 previous masks.
136 .Pp
137 The
138 .Fn fpgetsticky
139 function
140 returns the current floating point sticky flags.
141 .Pp
142 The
143 .Fn fpresetsticky
144 function
145 clears the floating point sticky flags and returns
146 the previous flags.
147 .Pp
148 Sample code which prevents a trap on divide-by-zero:
149 .Bd -literal -offset indent
150 fpsetmask(~FP_X_DZ);
151 a = 1.0;
152 b = 0;
153 c = a / b;
154 fpresetsticky(FP_X_DZ);
155 fpsetmask(FP_X_DZ);
156 .Ed
157 .Sh IMPLEMENTATION NOTES
158 The
159 .Fn fpgetprec
160 and
161 .Fn fpsetprec
162 functions provide functionality unavailable on many platforms.
163 At present, they are implemented only on the x86_64 platform.
164 Changing precision is not a supported feature:
165 it may be ineffective when code is compiled to take advantage of SSE,
166 and many library functions and compiler optimizations depend upon the
167 default precision for correct behavior.
168 .Sh SEE ALSO
169 .Xr fenv 3 ,
170 .Xr isnan 3
171 .Sh HISTORY
172 These routines are based on SysV/386 routines of the same name.
173 .Sh CAVEATS
174 After a floating point exception and before a mask is set, the sticky
175 flags must be reset.
176 If another exception occurs before the sticky
177 flags are reset, then a wrong exception type may be signaled.