xref: /dragonfly/share/man/man3/fpgetround.3 (revision 25a2db75)
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.15 2005/07/15 17:35:25 hrs Exp $
34.\" $DragonFly: src/share/man/man3/fpgetround.3,v 1.4 2008/05/02 02:05:05 swildner Exp $
35.\"
36.Dd April 23, 2009
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 fpsetsticky ,
48.Nm fpresetsticky
49.Nd IEEE floating point interface
50.Sh LIBRARY
51.Lb libc
52.Sh SYNOPSIS
53.In ieeefp.h
54.Bd -literal
55typedef enum {
56	FP_RN,		/* round to nearest */
57	FP_RM,		/* round down to minus infinity */
58	FP_RP,		/* round up to plus infinity */
59	FP_RZ		/* truncate */
60} fp_rnd_t;
61.Ed
62.Ft fp_rnd_t
63.Fn fpgetround void
64.Ft fp_rnd_t
65.Fn fpsetround "fp_rnd_t direction"
66.Bd -literal
67typedef enum {
68	FP_PS,		/* 24 bit (single-precision) */
69	FP_PRS,		/* reserved */
70	FP_PD,		/* 53 bit (double-precision) */
71	FP_PE		/* 64 bit (extended-precision) */
72} fp_prec_t;
73.Ed
74.Ft fp_prec_t
75.Fn fpgetprec void
76.Ft fp_prec_t
77.Fn fpsetprec "fp_prec_t precision"
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 fpsetsticky "fp_except_t sticky"
96.Ft fp_except_t
97.Fn fpresetsticky "fp_except_t sticky"
98.Sh DESCRIPTION
99The routines described herein are deprecated.
100New code should use the functionality provided by
101.Xr fenv 3 .
102.Pp
103When a floating point exception is detected, the exception sticky flag is
104set and the exception mask is tested.
105If the mask is set, then a trap occurs.
106These routines allow both setting the floating point exception
107masks, and resetting the exception sticky flags after an exception is
108detected.
109In addition, they allow setting the floating point rounding mode
110and precision.
111.Pp
112The
113.Fn fpgetround
114function
115returns the current floating point rounding mode.
116.Pp
117The
118.Fn fpsetround
119function
120sets the floating point rounding mode and returns
121the previous mode.
122.Pp
123The
124.Fn fpgetprec
125function
126returns the current floating point precision.
127.Pp
128The
129.Fn fpsetprec
130function
131sets the floating point precision and returns
132the previous precision.
133.Pp
134The
135.Fn fpgetmask
136function
137returns the current floating point exception masks.
138.Pp
139The
140.Fn fpsetmask
141function
142sets the floating point exception masks and returns the
143previous masks.
144.Pp
145The
146.Fn fpgetsticky
147function
148returns the current floating point sticky flags.
149.Pp
150The
151.Fn fpsetsticky
152sets the floating point sticky flags and returns
153the previous 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 IMPLEMENTATION NOTES
171The
172.Fn fpgetprec
173and
174.Fn fpsetprec
175functions provide functionality unavailable on many platforms.
176At present, they are implemented only on the i386 and x86_64 platforms.
177.Sh SEE ALSO
178.Xr fenv 3 ,
179.Xr isnan 3
180.Sh CAVEATS
181After a floating point exception and before a mask is set, the sticky
182flags must be reset.
183If another exception occurs before the sticky
184flags are reset, then a wrong exception type may be signaled.
185.Sh HISTORY
186These routines are based on SysV/386 routines of the same name.
187