2 ! { dg-require-effective-target fortran_largest_fp_has_sqrt }
4 ! This test checks whether the largest possible
5 ! floating-point number works.
7 ! This is a run-time check. Depending on the architecture,
8 ! this tests REAL(8), REAL(10) or REAL(16) and REAL(16)
9 ! might be a hardware or libquadmath 128bit number.
12 use iso_fortran_env
, only
: real_kinds
14 integer, parameter :: QP
= real_kinds(ubound(real_kinds
,dim
=1))
15 real(qp
) :: fp1
, fp2
, fp3
, fp4
16 character(len
=80) :: str1
, str2
, str3
, str4
20 write (str2
,'(g0)') fp1
22 write (str4
,'(g0)') fp2
24 ! print '(3a)', '>',trim(str1),'<'
25 ! print '(3a)', '>',trim(str2),'<'
26 ! print '(3a)', '>',trim(str3),'<'
27 ! print '(3a)', '>',trim(str4),'<'
30 if (fp1
/= fp3
) call abort()
32 if (fp1
/= fp3
) call abort()
34 if (abs (fp2
- fp4
)/fp2
> epsilon(fp2
)) call abort()
36 if (abs (fp2
- fp4
)/fp2
> epsilon(fp2
)) call abort()
40 if (str1
/= " 1.0000000000000000") call abort()
41 if (str2
/= "1.0000000000000000") call abort()
42 if (str3
/= " 1.4142135623730951") call abort()
43 if (str4
/= "1.4142135623730951") call abort()
46 if (str1
/= " 1.00000000000000000000") call abort()
47 if (str2
/= "1.00000000000000000000") call abort()
48 if (str3
/= " 1.41421356237309504876") call abort()
49 if (str4
/= "1.41421356237309504876") call abort()
52 if (str1
/= " 1.00000000000000000000000000000000000") call abort()
53 if (str2
/= "1.00000000000000000000000000000000000") call abort()
55 if (digits(1.0_qp
) == 113) then
56 ! IEEE 754 binary 128 format
57 ! e.g. libquadmath/__float128 on i686/x86_64/ia64
58 if (str3
/= " 1.41421356237309504880168872420969798") call abort()
59 if (str4
/= "1.41421356237309504880168872420969798") call abort()
60 else if (digits(1.0_qp
) == 106) then
61 ! IBM binary 128 format
62 if (str3(1:37) /= " 1.41421356237309504880168872420969") call abort()
63 if (str4(1:34) /= "1.41421356237309504880168872420969") call abort()
66 ! Do a libm run-time test
68 real(qp
), volatile :: fp2a
71 if (abs (fp2a
- fp2
) > sqrt(2.0_qp
)-nearest(sqrt(2.0_qp
),-1.0_qp
)) call abort()