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