24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

lock data<br />

include ’fpdc.h’<br />

include ’fpdt.h’<br />

end<br />

<strong>XL</strong> <strong>Fortran</strong> also provides several procedures that allow you to control the<br />

floating-point status and control register of the processor directly. These procedures<br />

are more efficient than the fpsets and fpgets subroutines because they are mapped<br />

into inlined machine instructions that manipulate the floating-point status and<br />

control register (fpscr) directly.<br />

<strong>XL</strong> <strong>Fortran</strong> supplies the get_round_mode() and set_round_mode() procedures in<br />

the xlf_fp_util module. These procedures return and set the current floating-point<br />

rounding mode, respectively.<br />

For example:<br />

program fptest<br />

use, intrinsic :: xlf_fp_util<br />

integer(fpscr_kind) old_fpscr<br />

if ( get_round_mode() == fp_rnd_rn ) then<br />

print *, ’Be<strong>for</strong>e test: Rounding mode is towards nearest’<br />

print *, ’ 2.0 / 3.0 = ’, 2.0 / 3.0<br />

print *, ’ -2.0 / 3.0 = ’, -2.0 / 3.0<br />

end if<br />

old_fpscr = set_round_mode( fp_rnd_rp )<br />

r = 2.0 / 3.0<br />

print *, ’Round towards +infinity: 2.0 / 3.0 = ’, r<br />

old_fpscr = set_round_mode( fp_rnd_rm )<br />

r = -2.0 / 3.0<br />

print *, ’Round towards -infinity: -2.0 / 3.0 = ’, r<br />

end<br />

<strong>XL</strong> <strong>Fortran</strong> supplies the ieee_get_rounding_mode() and ieee_set_rounding_mode()<br />

procedures in the ieee_arithmetic module. These portable procedures retrieve and<br />

set the current floating-point rounding mode, respectively.<br />

For example:<br />

program fptest<br />

use, intrinsic :: ieee_arithmetic<br />

type(ieee_round_type) current_mode<br />

call ieee_get_rounding_mode( current_mode )<br />

if ( current_mode == ieee_nearest ) then<br />

print *, ’Be<strong>for</strong>e test: Rounding mode is towards nearest’<br />

print *, ’ 2.0 / 3.0 = ’, 2.0 / 3.0<br />

print *, ’ -2.0 / 3.0 = ’, -2.0 / 3.0<br />

end if<br />

call ieee_set_rounding_mode( ieee_up )<br />

r = 2.0 / 3.0<br />

print *, ’Round towards +infinity: 2.0 / 3.0 = ’, r<br />

call ieee_set_rounding_mode( ieee_down )<br />

r = -2.0 / 3.0<br />

print *, ’Round towards -infinity: -2.0 / 3.0 = ’, r<br />

end<br />

Notes:<br />

1. Extended-precision floating-point values must only be used in round-to-nearest<br />

mode.<br />

<strong>XL</strong> <strong>Fortran</strong> Floating-Point Processing 293

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!