Changing the rounding mode

Fred J. Tydeman tydemanatybor.com
Mon Nov 10 17:20:37 PST 1997


On Mon, 10 Nov 1997 22:35:45 +0100, Philippe Charman wrote:

>I just want to know where I can find information on 
>the fastest way to change the rounding mode.
>For instance, on solaris I use the system function 
>ieee_flags, but it appears to be rather slow :-(

C9X, the revision of the C language now in progress,
has added a function to set the rounding mode:

  #include <fenv.h>

  fesetround( FE_TONEAREST );
  fesetround( FE_UPWARD );
  fesetround( FE_DOWNWARD );
  fesetround( FE_TOWARDZERO );

The macros FE_TONEAREST, FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO
are defined in <fenv.h> if and only if the implemenatation
supports getting and setting the represented rounding direction
by the functions fegetround() and fesetround().

These functions and macros are part of the Floating-Point C
Extensions (FPCE) that came from the Numerical C Extensions
Group (NCEG).  Some C compilers are already supporting these
FPCE items.

As I recall, ieee_flags uses strings for some of its
arguments, so these FPCE functions should avoid the 
overhead of string compares and should be faster.

---
Fred J. Tydeman    +1 (512) 255-8696   Tydeman Consulting
3711 Del Robles    tydemanatybor.com   Programming, testing, numerics
Austin, Texas 78727                    Voting member of X3J11 (ANSI "C")
USA            Sample C9X+FPCE tests:  ftp://jump.net/pub/tybor/





More information about the Numeric-interest mailing list