2017-12-08 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gfortran.dg / quad_2.f90
blobf7a8a469861f8a0e8ba17464c12869d70076f9fb
1 ! { dg-do run { xfail hppa*-*-hpux* } }
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.
11 program test_qp
12 use iso_fortran_env, only: real_kinds
13 implicit none
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
17 fp1 = 1
18 fp2 = sqrt (2.0_qp)
19 write (str1,*) fp1
20 write (str2,'(g0)') fp1
21 write (str3,*) fp2
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),'<'
29 read (str1, *) fp3
30 if (fp1 /= fp3) call abort()
31 read (str2, *) fp3
32 if (fp1 /= fp3) call abort()
33 read (str3, *) fp4
34 if (abs (fp2 - fp4)/fp2 > epsilon(fp2)) call abort()
35 read (str4, *) fp4
36 if (abs (fp2 - fp4)/fp2 > epsilon(fp2)) call abort()
38 select case (qp)
39 case (8)
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()
45 case (10)
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()
51 case (16)
52 if (digits(1.0_qp) == 113) then
53 ! IEEE 754 binary 128 format
54 ! e.g. libquadmath/__float128 on i686/x86_64/ia64
55 if (str1 /= " 1.00000000000000000000000000000000000") call abort()
56 if (str2 /= "1.00000000000000000000000000000000000") call abort()
57 if (str3 /= " 1.41421356237309504880168872420969798") call abort()
58 if (str4 /= "1.41421356237309504880168872420969798") call abort()
59 else if (digits(1.0_qp) == 106) then
60 ! IBM binary 128 format
61 if (str1 /= " 1.0000000000000000000000000000000") call abort()
62 if (str2 /= "1.0000000000000000000000000000000") call abort()
63 if (str3(1:37) /= " 1.4142135623730950488016887242097") call abort()
64 if (str4(1:34) /= "1.4142135623730950488016887242097") call abort()
65 end if
67 ! Do a libm run-time test
68 block
69 real(qp), volatile :: fp2a
70 fp2a = 2.0_qp
71 fp2a = sqrt (fp2a)
72 if (abs (fp2a - fp2) > sqrt(2.0_qp)-nearest(sqrt(2.0_qp),-1.0_qp)) call abort()
73 end block
75 case default
76 call abort()
77 end select
79 end program test_qp