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

--- Comment #6 from Thomas Henlich <thenlich at users dot sourceforge.net> 
2011-05-19 08:05:32 UTC ---
(In reply to comment #5)

As a general rule, d specifies the number of significant digits in the result,
i.e. the number of digits counting from the first non-zero digit.

So in the example all numbers should be formatted with 2 significant digits,
i.e. 2 decimal digits if the value rounded to 2 significant digits is smaller
than 1, and 1 decimal digit if the value rounded to 2 significant digits is
larger than or equal to 1.

> implicit none
> integer, parameter :: RT = 8
> write(*, "(rc,f11.2,4x,'<RC')") .995_RT
> write(*, "(rc,g15.2,'<RC')") .995_RT
> write(*, "(rd,f11.2,4x,'<RD')") .995_RT
> write(*, "(rd,g15.2,'<RD')") .995_RT
> write(*, "(ru,f11.2,4x,'<RU')") .995_RT
> write(*, "(ru,g15.2,'<RU')") .995_RT
> write(*,'(a)') "12345678901234567890"
> end

       0.99    <RC
       0.99    <RC
       0.99    <RD
       0.99    <RD
       1.00    <RU
        1.0    <RU
12345678901234567890

and
  write(*, "(ru,f11.1,4x,'<RU')") .995_RT
gets
        1.0    <RU

Reply via email to