#include <sys/ieeefp.h>
int ieee_flags(action, mode, in, out) char *action, *mode, *in, **out;
This function provides easy access to the modes and status required to fully exploit ANSI/IEEE Std 754-1985 arithmetic in a C program. All arguments are pointers to strings. Results arising from invalid arguments and invalid combinations are undefined for efficiency.
There are four types of action: get, set, clear and clearall. There are three valid settings for mode, two corresponding to modes of IEEE arithmetic:
and one corresponding to status of IEEE arithmetic:
There are fourteen types of in and out:
Note: all and common only make sense with set or clear.
For clearall, ieee_flags() returns 0 and restores all default modes and status. Nothing will be assigned to out. Thus
char *mode, *out, *in; ieee_flags("clearall", mode, in, &out);
set rounding direction to
nearest,
rounding precision to
extended,
and all accrued exception-occurred status to zero.
For clear, ieee_flags() returns 0 and restores the default mode or status. Nothing will be assigned to out. Thus
char *out, *in; ieee_flags("clear", "direction", in, &out); ... set rounding direction to round to nearest.
For set, ieee_flags() returns 0 if the action is successful and 1 if the corresponding required status or mode is not available (for instance, not supported in hardware). Nothing will be assigned to out. Thus
char *out, *in; ieee_flags ("set", "direction", "tozero", &out); set rounding direction to round toward zero;
For get, we have the following cases:
Case 1: mode is direction. In that case, out returns one of the four strings nearest, tozero, positive, negative, and ieee_flags() returns a value corresponding to out according to the enum fp_direction_type defined in <sys/ieeefp.h>.
Case 2:
mode
is
precision.
In that case,
out
returns one of the three strings
extended,
double
and
single,
and
ieee_flags()
returns a value corresponding to
out
according to the
enum fp_precision_type
defined in
<sys/ieeefp.h>.
Case 3: mode is exception. In that case, out returns
the accrued exception that has the highest priority according to the following list:
the exception named by in invalid overflow division underflow inexact
In this case ieee_flags() returns a five or six bit value where each bit (see enum fp_exception_type in <sys/ieeefp.h>) corresponds to an exception-occurred accrued status flag: 0 = off, 1 = on. The bit corresponding to a particular exception varies among architectures (see <sys/ieeefp.h>).
Example:
char *out; int k, ieee_flags(); ieee_flags("clear", "exception", "all", &out); /* clear all accrued exceptions */ ... code that generates three exceptions: overflow, invalid, inexact ... k = ieee_flags("get", "exception", "overflow", &out);
then out is overflow, and on a Sun-3, k is 25.
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97