http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54159

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-02 
10:29:29 UTC ---
Just for completeness, one obtains exactly the same result with ifort 12.2,
which uses Intel's REAL(16) implementations. For your program, the result is:

  qpreal1 =    42246.3973278316589130554348230362
  qpreal2 =    42246.3973278316589130554348230362
  trunc qpreal1 =    42246.3973278317
  trunc qpreal2 =    42246.3973278317

However, if one explicitly specifies that more digits are shown, i.e.
'(a,f40.30)' and '(a,f30.20)', the result is:

  qpreal1 =     42246.397327831658913055434823036200
  qpreal2 =     42246.397327831658913055434823036194
  trunc qpreal1 =     42246.39732783166255103424
  trunc qpreal2 =     42246.39732783165527507663

which matches gfortran's result. (Recall that REAL(..., kind=dp) operates on
the binary (radix=2) representation, which often cannot simply be converted
into decimal; such as "0.1", which is not representable as (finite) binary
floating point number.

 * * *

I believe that the current implementation matches the rounding mode
IEEE_NEAREST. To get the same double-precision result, you have to forcefully
round to a specific direction, i.e. IEEE_TO_ZERO, IEEE_UP or IEEE_DOWN.

If gfortran had support for Fortran 2003's optional IEEE modules, you could
use, e.g.,
  CALL IEEE_SET_ROUNDING_MODE (IEEE_TO_ZERO)

Unfortunately, TR15580/Fortran 2003's IEEE modules is not yet supported. And as
some other features have a higher priority, it will take a while. Unless, of
course, you (or someone else) volunteers ...

Reply via email to