bc6e64036adf49114a74b22d0dd2bbf0838a3f10
[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 .Nd IEEE floating point interface
43 .Sh LIBRARY
44 .Lb libc
45 .Sh SYNOPSIS
46 .In ieeefp.h
47 .Bd -literal
48 typedef enum {
49         FP_RN,          /* round to nearest */
50         FP_RM,          /* round down to minus infinity */
51         FP_RP,          /* round up to plus infinity */
52         FP_RZ           /* truncate */
53 } fp_rnd_t;
54 .Ed
55 .Ft fp_rnd_t
56 .Fn fpgetround void
57 .Ft fp_rnd_t
58 .Fn fpsetround "fp_rnd_t direction"
59 .Bd -literal
60 typedef enum {
61         FP_PS,          /* 24 bit (single-precision) */
62         FP_PRS,         /* reserved */
63         FP_PD,          /* 53 bit (double-precision) */
64         FP_PE           /* 64 bit (extended-precision) */
65 } fp_prec_t;
66 .Ed
67 .Ft fp_prec_t
68 .Fn fpgetprec void
69 .Ft fp_prec_t
70 .Fn fpsetprec "fp_prec_t precision"
71 .Bd -literal
72 #define fp_except_t     int
73 #define FP_X_INV        0x01    /* invalid operation */
74 #define FP_X_DNML       0x02    /* denormal */
75 #define FP_X_DZ         0x04    /* zero divide */
76 #define FP_X_OFL        0x08    /* overflow */
77 #define FP_X_UFL        0x10    /* underflow */
78 #define FP_X_IMP        0x20    /* (im)precision */
79 #define FP_X_STK        0x40    /* stack fault */
80 .Ed
81 .Ft fp_except_t
82 .Fn fpgetmask void
83 .Ft fp_except_t
84 .Fn fpsetmask "fp_except_t mask"
85 .Ft fp_except_t
86 .Fn fpgetsticky void
87 .Sh DESCRIPTION
88 The routines described herein are deprecated.
89 New code should use the functionality provided by
90 .Xr fenv 3 .
91 .Pp
92 When a floating point exception is detected, the exception sticky flag is
93 set and the exception mask is tested.
94 If the mask is set, then a trap occurs.
95 These routines allow both setting the floating point exception
96 masks, and resetting the exception sticky flags after an exception is
97 detected.
98 In addition, they allow setting the floating point rounding mode
99 and precision.
100 .Pp
101 The
102 .Fn fpgetround
103 function
104 returns the current floating point rounding mode.
105 .Pp
106 The
107 .Fn fpsetround
108 function
109 sets the floating point rounding mode and returns
110 the previous mode.
111 .Pp
112 The
113 .Fn fpgetprec
114 function
115 returns the current floating point precision.
116 .Pp
117 The
118 .Fn fpsetprec
119 function
120 sets the floating point precision and returns
121 the previous precision.
122 .Pp
123 The
124 .Fn fpgetmask
125 function
126 returns the current floating point exception masks.
127 .Pp
128 The
129 .Fn fpsetmask
130 function
131 sets the floating point exception masks and returns the
132 previous masks.
133 .Pp
134 The
135 .Fn fpgetsticky
136 function
137 returns the current floating point sticky flags.
138 .Sh IMPLEMENTATION NOTES
139 The
140 .Fn fpgetprec
141 and
142 .Fn fpsetprec
143 functions provide functionality unavailable on many platforms.
144 At present, they are implemented only on the x86_64 platform.
145 Changing precision is not a supported feature:
146 it may be ineffective when code is compiled to take advantage of SSE,
147 and many library functions and compiler optimizations depend upon the
148 default precision for correct behavior.
149 .Sh SEE ALSO
150 .Xr fenv 3 ,
151 .Xr isnan 3
152 .Sh HISTORY
153 These routines are based on SysV/386 routines of the same name.
154 .Sh CAVEATS
155 After a floating point exception and before a mask is set, the sticky
156 flags must be reset.
157 If another exception occurs before the sticky
158 flags are reset, then a wrong exception type may be signaled.