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