PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gfortran.dg / quad_2.f90
blobd03f37864e226ada31ccd732e581254922e0d445
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) STOP 1
31 read (str2, *) fp3
32 if (fp1 /= fp3) STOP 2
33 read (str3, *) fp4
34 if (abs (fp2 - fp4)/fp2 > epsilon(fp2)) STOP 3
35 read (str4, *) fp4
36 if (abs (fp2 - fp4)/fp2 > epsilon(fp2)) STOP 4
38 select case (qp)
39 case (8)
40 if (str1 /= " 1.0000000000000000") STOP 5
41 if (str2 /= "1.0000000000000000") STOP 6
42 if (str3 /= " 1.4142135623730951") STOP 7
43 if (str4 /= "1.4142135623730951") STOP 8
45 case (10)
46 if (str1 /= " 1.00000000000000000000") STOP 9
47 if (str2 /= "1.00000000000000000000") STOP 10
48 if (str3 /= " 1.41421356237309504876") STOP 11
49 if (str4 /= "1.41421356237309504876") STOP 12
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") STOP 13
56 if (str2 /= "1.00000000000000000000000000000000000") STOP 14
57 if (str3 /= " 1.41421356237309504880168872420969798") STOP 15
58 if (str4 /= "1.41421356237309504880168872420969798") STOP 16
59 else if (digits(1.0_qp) == 106) then
60 ! IBM binary 128 format
61 if (str1 /= " 1.0000000000000000000000000000000") STOP 17
62 if (str2 /= "1.0000000000000000000000000000000") STOP 18
63 if (str3(1:37) /= " 1.4142135623730950488016887242097") STOP 19
64 if (str4(1:34) /= "1.4142135623730950488016887242097") STOP 20
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)) STOP 21
73 end block
75 case default
76 STOP 22
77 end select
79 end program test_qp