]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man3/fpgetround.3
This commit was generated by cvs2svn to compensate for changes in r55839,
[FreeBSD/FreeBSD.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 .Fd #include <ieeefp.h>
50 .Ft typedef enum {
51 .br
52 .Fa     FP_RN,  
53 .Li             /* round to nearest */
54 .br
55 .Fa     FP_RM,  
56 .Li             /* round to minus infinity */
57 .br
58 .Fa     FP_RP,  
59 .Li             /* round to plus infinity */
60 .br
61 .Fa     FP_RZ,  
62 .Li             /* truncate */
63 .br
64 .Ft } fp_rnd_t;
65 .Pp
66 .Ft fp_rnd_t
67 .Fn fpgetround void
68 .Ft fp_rnd_t
69 .Fn fpsetround "fp_rnd_t direction"
70 .Pp
71 .nr fZ 0
72 .Ft typedef enum {
73 .br
74 .Fa     FP_PS,  
75 .Li             /* 24 bit (single-precision) */
76 .br
77 .Fa     FP_PRS, 
78 .Li             /* reserved */
79 .br
80 .Fa     FP_PD,  
81 .Li             /* 53 bit (double-precision) */
82 .br
83 .Fa     FP_PE,  
84 .Li             /* 64 bit (extended-precision) */
85 .br
86 .Ft } fp_prec_t;
87 .Pp
88 .Ft fp_prec_t
89 .Fn fpgetprec void
90 .Ft fp_prec_t
91 .Fn fpsetprec "fp_prec_t precision"
92 .Pp
93 .Fd #define fp_except_t int
94 .Fd #define FP_X_INV    0x01            /* invalid */
95 .Fd #define FP_X_OFL    0x08            /* overflow */
96 .Fd #define FP_X_UFL    0x10            /* underflow */
97 .Fd #define FP_X_DZ     0x04            /* divide-by-zero */
98 .Fd #define FP_X_IMP    0x20            /* loss of precision */
99 .Fd #define FP_X_DNML   0x02            /* denormal */
100 .Ft fp_except_t
101 .Fn fpgetmask void
102 .Ft fp_except_t
103 .Fn fpsetmask "fp_except_t mask"
104 .Ft fp_except_t
105 .Fn fpgetsticky void
106 .Ft fp_except_t
107 .Fn fpresetsticky "fp_except_t sticky"
108 .Sh DESCRIPTION
109 When a floating point exception is detected, the exception sticky flag is
110 set and the exception mask is tested. If the mask is set, then a trap
111 occurs.  These routines allow both setting the floating point exception
112 masks, and  resetting the exception sticky flags after an exception is
113 detected.  In addition, they allow setting the floating point rounding mode
114 and precision.
115 .Pp
116 The
117 .Fn fpgetround
118 function
119 returns the current floating point rounding mode.
120 .Pp
121 The
122 .Fn fpsetround
123 function
124 sets the floating point rounding mode and returns
125 the previous mode.
126 .Pp
127 The
128 .Fn fpgetprec
129 function
130 returns the current floating point precision.
131 .Pp
132 The
133 .Fn fpsetprec
134 function
135 sets the floating point precision and returns
136 the previous precision.
137 .Pp
138 The
139 .Fn fpgetmask
140 function
141 returns the current floating point exception masks.
142 .Pp
143 The
144 .Fn fpsetmask
145 function
146 sets the floating point exception masks and returns the
147 previous masks.
148 .Pp
149 The
150 .Fn fpgetsticky
151 function
152 returns the current floating point sticky flags.
153 .Pp
154 The
155 .Fn fpresetsticky
156 function
157 clears the floating point sticky flags and returns
158 the previous flags.
159 .Pp
160 Sample code which prevents a trap on divide-by-zero:
161 .Bd -literal -offset indent
162 fpsetmask(~FP_X_DZ);
163 a = 1.0;
164 b = 0;
165 c = a / b;
166 fpresetsticky(FP_X_DZ);
167 fpsetmask(FP_X_DZ);
168 .Ed
169 .Sh SEE ALSO
170 .Xr isnan 3
171 .Sh CAVEAT
172 After a floating point exception and before a mask is set, the sticky
173 flags must be reset.  If another exception occurs before the sticky
174 flags are reset, then a wrong exception type may be signaled.
175 .Sh HISTORY
176 These routines are based on SysV/386 routines of the same name.