Oracle® Solaris Studio 12.4: Numerical Computation Guide

Exit Print View

Updated: January 2015
 
 

3.4.3 ieee_flags(3m)

ieee_flags (3m) is the Oracle interface to:

  • Query or set rounding direction mode

  • Query or set rounding precision mode

  • Examine, clear, or set accrued exception flags

The syntax for a call to ieee_flags(3m) is:

i = ieee_flags(action, mode, in, out);

The ASCII strings that are the possible values for the parameters are shown in Table 3–13:

Table 3-13  Parameter Values for ieee_flags
Parameter
C or C++ Type
All Possible Values
action
char *
get, set, clear, clearall
mode
char *
direction, precision, exception
in
char *
nearest, tozero, negative, positive, extended, double, single, inexact, division, underflow, overflow, invalid, all, common
out
char **
nearest, tozero, negative, positive, extended, double, single, inexact, division, underflow, overflow, invalid, all, common

The ieee_flags(3m) man page describes the parameters in complete detail.

Some of the arithmetic features that can be modified by using ieee_flags are covered in the following paragraphs. Chapter 4 contains more information on ieee_flags and IEEE exception flags.

When mode is direction, the specified action applies to the current rounding direction. The possible rounding directions are: round towards nearest, round towards zero, round towards +•, or round towards −•. The IEEE default rounding direction is round towards nearest. This means that when the mathematical result of an operation lies strictly between two adjacent representable numbers, the one nearest to the mathematical result is delivered. (If the mathematical result lies exactly halfway between the two nearest representable numbers, then the result delivered is the one whose least significant bit is zero. The round towards nearest mode is sometimes called round to nearest even to emphasize this.)

Rounding towards zero is the way many pre-IEEE computers work, and corresponds mathematically to truncating the result. For example, if 2/3 is rounded to 6 decimal digits, the result is .666667 when the rounding mode is round towards nearest, but .666666 when the rounding mode is round towards zero.

When using ieee_flags to examine, clear, or set the rounding direction, possible values for the four input parameters are shown in Table 3–14.

Table 3-14  ieee_flags Input Values for the Rounding Direction
Parameter
Possible value (mode is direction)
action
get, set, clear, clearall
in
nearest, tozero, negative, positive
out
nearest, tozero, negative, positive

When mode is precision, the specified action applies to the current rounding precision. On x86-based systems, the possible rounding precisions are: single, double, and extended. The default rounding precision is extended; in this mode, arithmetic operations that deliver a result to an x87 floating-point register round their result to the full 64-bit precision of the extended double register format. When the rounding precision is single or double, arithmetic operations that deliver a result to an x87 floating-point register round their result to 24 or 53 significant bits, respectively. Although most programs produce results that are at least as accurate, if not more so, when extended rounding precision is used, some programs that require strict adherence to the semantics of IEEE arithmetic will not work correctly in extended rounding precision mode and must be run with the rounding precision set to single or double as appropriate.

Rounding precision cannot be set on systems using SPARC processors. On these systems, calling ieee_flags with mode = precision has no effect on computation.

Finally, when mode is exception, the specified action applies to the current IEEE exception flags. See Chapter 4, Exceptions and Exception Handling for more information about using ieee_flags to examine and control the IEEE exception flags.