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