xref: /freebsd/share/man/man3/fpgetround.3 (revision df7f5d4de4592a8948a25ce01e5bddfbb7ce39dc)
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.\"	$Id: fpgetround.3,v 1.3 1997/03/07 03:27:53 jmg Exp $
34.\"
35.Dd August 23, 1993
36.Dt FPGETROUND 3
37.Os
38.Sh NAME
39.Nm fpgetround ,
40.Nm fpsetround ,
41.Nm fpgetmask ,
42.Nm fpsetmask ,
43.Nm fpgetsticky ,
44.Nm fpresetsticky
45.Nd IEEE floating point interface
46.Sh SYNOPSIS
47.Fd #include <floatingpoint.h>
48.Ft typedef enum {
49.br
50.Fa 	FP_RN,
51.Li		/* round to nearest */
52.br
53.Fa 	FP_RM,
54.Li		/* round to minus infinity */
55.br
56.Fa 	FP_RP,
57.Li		/* round to plus infinity */
58.br
59.Fa 	FP_RZ,
60.Li		/* truncate */
61.br
62.Ft } fp_rnd;
63.Pp
64.Ft fp_rnd
65.Fn fpgetround void
66.Ft fp_rnd
67.Fn fpsetround "fp_rnd direction"
68.Fd #define fp_except int
69.Fd #define FP_X_INV	0x01		/* invalid */
70.Fd #define FP_X_OFL	0x08		/* overflow */
71.Fd #define FP_X_UFL	0x10		/* underflow */
72.Fd #define FP_X_DZ	0x04		/* divide-by-zero */
73.Fd #define FP_X_IMP	0x20		/* loss of precision */
74.Fd #define FP_X_DNML	0x02		/* denormal */
75.Ft fp_except
76.Fn fpgetmask void
77.Ft fp_except
78.Fn fpsetmask "fp_except mask"
79.Ft fp_except
80.Fn fpgetsticky void
81.Ft fp_except
82.Fn fpresetsticky "fp_except sticky"
83.Sh DESCRIPTION
84When a floating point exception is detected, the exception sticky flag is
85set and the exception mask is tested. If the mask is set, then a trap
86occurs.  These routines allow both setting the floating point exception
87masks, and  resetting the exception sticky flags after an exception is
88detected.  In addition, they allow setting the floating point rounding mode.
89.Pp
90The
91.Fn fpgetround
92function
93returns the current floating point rounding mode.
94.Pp
95The
96.Fn fpsetround
97function
98sets the floating point rounding mode and returns
99the previous mode.
100.Pp
101The
102.Fn fpgetmask
103function
104returns the current floating point exception masks.
105.Pp
106The
107.Fn fpsetmask
108function
109sets the floating point exception masks and returns the
110previous masks.
111.Pp
112The
113.Fn fpgetsticky
114function
115returns the current floating point sticky flags.
116.Pp
117The
118.Fn fpresetsticky
119function
120clears the floating point sticky flags and returns
121the previous flags.
122.Pp
123Sample code which prevents a trap on divide-by-zero:
124.Bd -literal -offset indent
125fpsetmask(~FP_X_DZ);
126a = 1.0;
127b = 0;
128c = a / b;
129fpresetsticky(FP_X_DZ);
130fpsetmask(FP_X_DZ);
131.Ed
132.Sh SEE ALSO
133.Xr isnan 3
134.Sh CAVEAT
135After a floating point exception and before a mask is set, the sticky
136flags must be reset.  If another exception occurs before the sticky
137flags are reset, then a wrong exception type may be signaled.
138.Sh HISTORY
139These routines are based on SysV/386 routines of the same name.
140