Wilfred,
I added to your example to show other alternatives for implied precision in a calculation.
I also calculated the error, both using the atan calculation and then using a temporary variable of defined precision. If you note the reporting of the error term 'pi-a*atan(b)' it appears that atan(b) is calculated and retained as 80 bit precision, even though 32 bit is all that is implied.
{ I only note this and do not suggest that the compiler should be changed to produce 32bit precision for atan(b). }
The code is:
program test
real*4 a,b,c
real*8 x,y,z
real*10 r,s,t, pi
!
pi = 3.1415926535897932384626_3
write (6,'(A)') '3.1415926535897932384626' ! correct value
write (6,22) pi, 'pi_r*10'
22 format (F24.22,2x,a,2es12.2)
write (6,22) 4.D0*datan(1.D0), '4.D0*datan(1.D0)', pi-4.D0*datan(1.D0)
a = 4.
b = 1.
x = 4.
y = 1.
r = 4.
s = 1.
c = a*atan(b) ; write (6,22) a*atan(b), 'a*atan(b)', pi-a*atan(b), pi-c
z = x*atan(y) ; write (6,22) x*atan(y), 'x*atan(y)', pi-x*atan(y), pi-z
t = r*atan(s) ; write (6,22) r*atan(s), 'r*atan(s)', pi-r*atan(s), pi-t
!
c = 4*atan(b) ; write (6,22) 4*atan(b), '4*atan(b)', pi-4*atan(b), pi-c
z = 4*atan(y) ; write (6,22) 4*atan(y), '4*atan(y)', pi-4*atan(y), pi-z
t = 4*atan(s) ; write (6,22) 4*atan(s), '4*atan(s)', pi-4*atan(s), pi-t
!
end
Compilation was ftn95 pi.f95 /lgo
The results are:
[FTN95/Win32 Ver. 6.30.0 Copyright (c) Silverfrost Ltd 1993-2012]
NO ERRORS [<TEST> FTN95/Win32 v6.30.0]
Creating executable: c:\temp\lgotemp@.exe
Program entered
3.1415926535897932384626
3.1415926535897932386000 pi_r*10
3.1415926535897931160000 4.D0*datan(1.D0) 1.23E-16
3.1415927410125732423000 a*atan(b) 0.00E+00 -8.74E-08
3.1415926535897931160000 x*atan(y) 0.00E+00 1.23E-16
3.1415926535897932386000 r*atan(s) 0.00E+00 0.00E+00
3.1415927410125732423000 4*atan(b) 0.00E+00 -8.74E-08
3.1415926535897931160000 4*atan(y) 0.00E+00 1.23E-16
3.1415926535897932386000 4*atan(s) 0.00E+00 0.00E+00
John