! Calculates:
! sum:   x +a -x
! sum_1: x -x +a
! x =1.25*10^n
! a = small
!
! Compile with: Floating-Point Model: strict
! Single, Double, and Quad precision

use dflib

real(4) x, a
real(8) x8, a8
real(16) x16, a16
character(100) fname, c*80

write(*,'(a)') 'Calculation of sums:' 
write(*,'(a)') 'sum = x+a-x'
write(*,'(a)') 'sum_1 = x-x+a'
write(*,'(a)') 'x = "very large"', 'a = "small"'

write(*,'(/,a)') 'Output file name is: sum-C.rez'
write(*,'(a,\)') 'Input "C" (<= 80 chars): '
read(*,'(a)') c

fname ='Sum-'//trim(c)

open(1, file =fname, status ='unknown', form ='formatted')


x =1.25E8
a =5.5E0

write(1,'(a,/,a)') 'sum   = x +a -x', 'sum_1 = x -x +a;'

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

write(1,'(a, 1pG15.7)') ' x =', x
write(1,'(a, 1pG15.7)')    ' a =', a

write(1, '(/,a, 1pG15.7)'), ' sum =', x +a -x
write(1, '(a, 1pG15.7)'),   ' sum_1 =', x -x + a
!
write(1,*) '(x+a: ', x+a, ')'

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

x8 =1.25D8
a8 =5.5D0
write(1,'(a, 1pE24.16)') ' x =', x8
write(1,'(a, 1pG24.16)')    ' a =', a8

write(1,'(/,a, 1pG24.16)'), ' sum =', x8 + a8 -x8
write(1,'(a, 1pG24.16)'),   ' sum_1 =', x8 -x8 +a8
write(1,*) '(x+a: ', x8+a8, ')'


write(1, '(/,a)') '*'
x8 =1.25D16
a8 =55.D0

write(1,'(a, 1pG24.16)') ' x =', x8
write(1,'(a, 1pG24.16)')    ' a =', a8

write(1,'(/,a, 1pG24.16)'), ' sum =', x8 + a8 -x8
write(1,'(a, 1pG24.16)'),   ' sum_1 =', x8 -x8 +a8
write(1,*) '(x+a: ', x8+a8, ')'


! Cvadrupla:
write(1, '(/,a)') ' * Quadruple Precision (113):'
write(1, '(a)')   '   ------------------------'

x16 =1.25Q34
a16 =5555.Q0

write(1,'(a, 1pE30.18)') ' x =', x16
write(1,'(   a, 1pG30.18)') ' a =', a16

write(1, '(/,a, 1pG30.18)'), ' sum   =', x16 +a16 -x16
write(1,'(a, 1pG30.18)'),    ' sum_1 =', x16 -x16 +a16
write(1,*) '(x+a: ', x16+16, ')'

write(1,'(/,a)') '*'
x16 =1.25Q32
a16 =5555.Q0

write(1,'(a, 1pE30.18)') ' x =', x16
write(1,'(   a, 1pG30.18)') ' a =', a16

write(1, '(/,a, 1pG30.18)'), ' sum   =', x16 +a16 -x16
write(1,'(a, 1pG30.18)'),    ' sum_1 =', x16 -x16 +a16
write(1,*) '(x+a: ', x16+a16, ')'

write(*,*) ' Output File: "', trim(fname), '"'
END
