Main index | Section 3 | 日本語 | Options |
#include <ieeefp.h>
typedef enum { FP_RN, /* round to nearest */ FP_RM, /* round down to minus infinity */ FP_RP, /* round up to plus infinity */ FP_RZ /* truncate */ } fp_rnd_t;
typedef enum { FP_PS, /* 24 bit (single-precision) */ FP_PRS, /* reserved */ FP_PD, /* 53 bit (double-precision) */ FP_PE /* 64 bit (extended-precision) */ } fp_prec_t;
#define fp_except_t int #define FP_X_INV 0x01 /* invalid operation */ #define FP_X_DNML 0x02 /* denormal */ #define FP_X_DZ 0x04 /* zero divide */ #define FP_X_OFL 0x08 /* overflow */ #define FP_X_UFL 0x10 /* underflow */ #define FP_X_IMP 0x20 /* (im)precision */ #define FP_X_STK 0x40 /* stack fault */
When a floating point exception is detected, the exception sticky flag is set and the exception mask is tested. If the mask is set, then a trap occurs. These routines allow both setting the floating point exception masks, and resetting the exception sticky flags after an exception is detected. In addition, they allow setting the floating point rounding mode and precision.
The fpgetround() function returns the current floating point rounding mode.
The fpsetround() function sets the floating point rounding mode and returns the previous mode.
The fpgetprec() function returns the current floating point precision.
The fpsetprec() function sets the floating point precision and returns the previous precision.
The fpgetmask() function returns the current floating point exception masks.
The fpsetmask() function sets the floating point exception masks and returns the previous masks.
The fpgetsticky() function returns the current floating point sticky flags.
The fpresetsticky() function clears the floating point sticky flags and returns the previous flags.
Sample code which prevents a trap on divide-by-zero:
fpsetmask(~FP_X_DZ); a = 1.0; b = 0; c = a / b; fpresetsticky(FP_X_DZ); fpsetmask(FP_X_DZ);
FPGETROUND (3) | December 3, 2010 |
Main index | Section 3 | 日本語 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | Computer science would have progressed much further and faster if all of the time and effort that has been spent maintaining and nurturing Unix had been spent on a sounder operating system. | ” |
— The Unix Haters' handbook |