How do you plan to use the precision information?
As you state, the intrinsic function returns int( (digits(x)-1)*log10(radix(x)) ) as the decimal precision which is a functionally reasonable estimate of the number of significant decimal digits in the floating-point representation. A trivial illustration, given the near-ubiquitous use of IEEE floating-point arithmetic with processors, being
print *, "PI (binary32) = ", real( 4*atan(1D0) )
end
C:\Temp>a.exe
PI (binary32) = 3.141593
However for a lossless “round-trip” when it comes to precision, say during IO, adding 2 to the result returned by precision toward the d value for digits in data edit descriptors is practical though you need at least 7:
character(len=20) :: s
character(len=*), parameter :: fmts = "(es20.7)" !<-- Try with 6 for d
character(len=*), parameter :: fmtb = "(g0,b0)"
real :: x
write( s, fmt=fmts ) real( 4*atan(1D0) )
read( s, fmt=fmts ) x
print fmtb, "x(binary) = ", x
print fmtb, "Expected is ", real( 4*atan(1D0) )
end
C:\Temp>a.exe
x(binary) = 1000000010010010000111111011011
Expected is 1000000010010010000111111011011