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