Merge from vendor branch TNFTP:
[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. 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: src/share/man/man3/fpgetround.3,v 1.9.2.2 2001/12/17 11:30:11 ru Exp $
34 .\" $DragonFly: src/share/man/man3/fpgetround.3,v 1.2 2003/06/17 04:36:58 dillon Exp $
35 .\"
36 .Dd August 23, 1993
37 .Dt FPGETROUND 3
38 .Os
39 .Sh NAME
40 .Nm fpgetround ,
41 .Nm fpsetround ,
42 .Nm fpsetprec ,
43 .Nm fpgetprec ,
44 .Nm fpgetmask ,
45 .Nm fpsetmask ,
46 .Nm fpgetsticky ,
47 .Nm fpresetsticky
48 .Nd IEEE floating point interface
49 .Sh SYNOPSIS
50 .In ieeefp.h
51 .Pp
52 .Bd -literal
53 typedef enum {
54         FP_RN,          /* round to nearest */
55         FP_RM,          /* round down to minus infinity */
56         FP_RP,          /* round up to plus infinity */
57         FP_RZ           /* truncate */
58 } fp_rnd_t;
59 .Ed
60 .Ft fp_rnd_t
61 .Fn fpgetround void
62 .Ft fp_rnd_t
63 .Fn fpsetround "fp_rnd_t direction"
64 .Pp
65 .Bd -literal
66 typedef enum {
67         FP_PS,          /* 24 bit (single-precision) */
68         FP_PRS,         /* reserved */
69         FP_PD,          /* 53 bit (double-precision) */
70         FP_PE           /* 64 bit (extended-precision) */
71 } fp_prec_t;
72 .Ed
73 .Ft fp_prec_t
74 .Fn fpgetprec void
75 .Ft fp_prec_t
76 .Fn fpsetprec "fp_prec_t precision"
77 .Pp
78 .Bd -literal
79 #define fp_except_t     int
80 #define FP_X_INV        0x01    /* invalid operation */
81 #define FP_X_DNML       0x02    /* denormal */
82 #define FP_X_DZ         0x04    /* zero divide */
83 #define FP_X_OFL        0x08    /* overflow */
84 #define FP_X_UFL        0x10    /* underflow */
85 #define FP_X_IMP        0x20    /* (im)precision */
86 #define FP_X_STK        0x40    /* stack fault */
87 .Ed
88 .Ft fp_except_t
89 .Fn fpgetmask void
90 .Ft fp_except_t
91 .Fn fpsetmask "fp_except_t mask"
92 .Ft fp_except_t
93 .Fn fpgetsticky void
94 .Ft fp_except_t
95 .Fn fpresetsticky "fp_except_t sticky"
96 .Sh DESCRIPTION
97 When a floating point exception is detected, the exception sticky flag is
98 set and the exception mask is tested.
99 If the mask is set, then a trap
100 occurs.  These routines allow both setting the floating point exception
101 masks, and  resetting the exception sticky flags after an exception is
102 detected.  In addition, they allow setting the floating point rounding mode
103 and precision.
104 .Pp
105 The
106 .Fn fpgetround
107 function
108 returns the current floating point rounding mode.
109 .Pp
110 The
111 .Fn fpsetround
112 function
113 sets the floating point rounding mode and returns
114 the previous mode.
115 .Pp
116 The
117 .Fn fpgetprec
118 function
119 returns the current floating point precision.
120 .Pp
121 The
122 .Fn fpsetprec
123 function
124 sets the floating point precision and returns
125 the previous precision.
126 .Pp
127 The
128 .Fn fpgetmask
129 function
130 returns the current floating point exception masks.
131 .Pp
132 The
133 .Fn fpsetmask
134 function
135 sets the floating point exception masks and returns the
136 previous masks.
137 .Pp
138 The
139 .Fn fpgetsticky
140 function
141 returns the current floating point sticky flags.
142 .Pp
143 The
144 .Fn fpresetsticky
145 function
146 clears the floating point sticky flags and returns
147 the previous flags.
148 .Pp
149 Sample code which prevents a trap on divide-by-zero:
150 .Bd -literal -offset indent
151 fpsetmask(~FP_X_DZ);
152 a = 1.0;
153 b = 0;
154 c = a / b;
155 fpresetsticky(FP_X_DZ);
156 fpsetmask(FP_X_DZ);
157 .Ed
158 .Sh SEE ALSO
159 .Xr isnan 3
160 .Sh CAVEAT
161 After a floating point exception and before a mask is set, the sticky
162 flags must be reset.  If another exception occurs before the sticky
163 flags are reset, then a wrong exception type may be signaled.
164 .Sh HISTORY
165 These routines are based on SysV/386 routines of the same name.