! Calculates sum: 1.25*10^20 -555.55 -1.25*10^20
! Compile with: Optimizations = NONE
!
! Single & Double precision

use dflib

real(4) x1, x2, x3, ssum
real(8) xx1, xx2, xx3, dsum

!sum1 =1.25E10 -555.55 -1.25E10
!sum2 =1.25E10 -1.25E10 -555.55

ssum(x1,x2,x3) =x1 +x2 +x3
dsum(xx1,xx2,xx3) =xx1 +xx2 +xx3

open(1, file ='sum-cvf.rez', status ='unknown', form ='formatted')

write(1, '(/,a)') ' * Single Precision (24):'

!x1 =1.25E20
!x2 =555.5
!x3 =-x1

x1 =1.25E9
x2 =5.
x3 =-x1


write(1,'(/, a, 1pG15.7)') ' x1 =', x1
write(1,'(a, 1pG15.7)')    ' x2 =', x2
write(1,'(a, 1pG15.7)')    ' x3 =', x3

write(1, '(/,a, 1pG15.7)'), ' x1 +x2 +x3 =', ssum(x1, x2, x3)
write(1, '(a, 1pG15.7)'),   ' x1 +x3 +x2 =', ssum(x1, x3, x2)

write(1, '(/,a)') ' * Double Precision (53):'

!xx1 =1.25D20
!xx2 =555.5D0
!xx3 =-xx1

xx1 =1.25D16
xx2 =5D0
xx3 =-xx1

write(1,'(/, a, 1pG24.16)') ' x1 =', x1
write(1,'(a, 1pG24.16)')    ' x2 =', x2
write(1,'(a, 1pG24.16)')    ' x3 =', x3

write(1,'(/,a, 1pG24.16)'), ' x1 +x2 +x3 =', dsum(xx1, xx2, xx3)
write(1,'(a, 1pG24.16)'),   ' x1 +x3 +x2 =', dsum(xx1, xx3, xx2)

call FPprecis(FPCW$64)
write(1, '(/,a)') ' * Extended Precision (64):'

!x1 =1.25E20
!x2 =555.5
!x3 =-x1

x1 =1.25E16
x2 =5.E0
x3 =-x1

write(1,'(/, a, 1pE30.18)') ' x1 =', x1
write(1,'(a, 1pE30.18)') ' x2 =', x2
write(1,'(a, 1pE30.18)') ' x3 =', x3

write(1, '(/,a, 1pE30.18)'), ' x1 +x2 +x3 =', ssum(x1,x2,x3)
write(1,'(a, 1pE30.18)'),    ' x1 +x3 +x2 =', ssum(x1,x3,x2), x1 +x3 +x2


write(*,*) ' Output File: "sum-cvf.rez"'
END
