IEEE 754 rounding mode support -- a survey

Fred Tydeman uunet!ibminet.awdpa.ibm.com!ibmpa!tydeman
Mon May 18 09:39:11 PDT 1992


 
Your description of the IBM RISC System/6000 rounding mode selection is
incomplete.
 
In C, the following routines are available:
  FLT_ROUNDS
  fp_read_rnd()
  fp_swap_rnd( fprnd_t )
 
The Standard C macro FLT_ROUNDS, found in <float.h>, expands into a
call to the fp_read_rnd() function to get the current rounding mode.
 
The fp_swap_rnd function gets the current rounding mode, as its return
value, and sets the rounding mode to its argument's value.
 
A typical usage is:
 
save_mode = fp_swap_rnd( new_mode );  /* Get current rounding mode.
                                      Set rounding to the new_mode */
... desired code using new mode ...
(void) fp_swap_rnd( save_mode );  /* Restore the saved rounding mode */
 
new_mode would be one of:
  FP_RND_RN  -- round to nearest
  FP_RND_RZ  -- round toward zero
  FP_RND_RP  -- round toward plus infinity
  FP_RND_RM  -- round toward minus infinity
 
In FORTRAN, there are routines to get and to set the floating-point
status and control register, which includes the rounding mode bits.
There is sample code in appendix B, the run time environment, of the
version 2.2 FORTRAN language reference manual SC09-1353, that shows how
to change the rounding mode.
 
Fred Tydeman, IBM, Austin, Texas (512) 838-3322; fax (512) 838-3484
AIX S/6000 Floating-point architect & IBM's rep to NCEG (X3J11.1)
Internet: tydemanaibmpa.awdpa.ibm.com    uucp: uunet!ibmsupt!tydeman



More information about the Numeric-interest mailing list