xref: /freebsd/share/man/man3/fpgetround.3 (revision 77a0943ded95b9e6438f7db70c4a28e4d93946d4)
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
109When a floating point exception is detected, the exception sticky flag is
110set and the exception mask is tested.
111If the mask is set, then a trap
112occurs.  These routines allow both setting the floating point exception
113masks, and  resetting the exception sticky flags after an exception is
114detected.  In addition, they allow setting the floating point rounding mode
115and precision.
116.Pp
117The
118.Fn fpgetround
119function
120returns the current floating point rounding mode.
121.Pp
122The
123.Fn fpsetround
124function
125sets the floating point rounding mode and returns
126the previous mode.
127.Pp
128The
129.Fn fpgetprec
130function
131returns the current floating point precision.
132.Pp
133The
134.Fn fpsetprec
135function
136sets the floating point precision and returns
137the previous precision.
138.Pp
139The
140.Fn fpgetmask
141function
142returns the current floating point exception masks.
143.Pp
144The
145.Fn fpsetmask
146function
147sets the floating point exception masks and returns the
148previous masks.
149.Pp
150The
151.Fn fpgetsticky
152function
153returns the current floating point sticky flags.
154.Pp
155The
156.Fn fpresetsticky
157function
158clears the floating point sticky flags and returns
159the previous flags.
160.Pp
161Sample code which prevents a trap on divide-by-zero:
162.Bd -literal -offset indent
163fpsetmask(~FP_X_DZ);
164a = 1.0;
165b = 0;
166c = a / b;
167fpresetsticky(FP_X_DZ);
168fpsetmask(FP_X_DZ);
169.Ed
170.Sh SEE ALSO
171.Xr isnan 3
172.Sh CAVEAT
173After a floating point exception and before a mask is set, the sticky
174flags must be reset.  If another exception occurs before the sticky
175flags are reset, then a wrong exception type may be signaled.
176.Sh HISTORY
177These routines are based on SysV/386 routines of the same name.
178