Debian Codegraph @

gcc/testsuite/gfortran.dg/out_of_range_1.f90

raw
1 ! { dg-do run }
2 !
3 ! PR fortran/115788 - OUT_OF_RANGE
4
5 program p
6 use iso_fortran_env, only: int8, int64, real32, real64
7 implicit none
8 integer :: i
9 integer(int8) :: i1
10 integer(int64) :: i8
11 real(real32) :: r
12 real(real64) :: d
13 logical :: t = .true., f = .false.
14
15 real, parameter :: a(*) = [-128.5, -127.5, 126.5, 127.5]
16 logical, parameter :: l1(*) = OUT_OF_RANGE (a, 0_int8)
17 logical, parameter :: l2(*) = OUT_OF_RANGE (a, 0_int8, .true.)
18 logical, parameter :: expect1(*) = [.false.,.false.,.false.,.false.]
19 logical, parameter :: expect2(*) = [.true. ,.false.,.false.,.true. ]
20 real :: b(size(a)) = a
21
22 ! Check for correct truncation or rounding, compile-time
23 if (any (l1 .neqv. expect1)) stop 1
24 if (any (l2 .neqv. expect2)) stop 2
25
26 ! Check for correct truncation or rounding, run-time
27 if (any (OUT_OF_RANGE (a, 0_int8, f) .neqv. expect1)) stop 3
28 if (any (OUT_OF_RANGE (a, 0_int8, t) .neqv. expect2)) stop 4
29
30 if (any (OUT_OF_RANGE (b, 0_int8) .neqv. expect1)) stop 5
31 if (any (OUT_OF_RANGE (b, 0_int8, .false.) .neqv. expect1)) stop 6
32 if (any (OUT_OF_RANGE (b, 0_int8, .true.) .neqv. expect2)) stop 7
33 if (any (OUT_OF_RANGE (b, 0_int8, f) .neqv. expect1)) stop 8
34 if (any (OUT_OF_RANGE (b, 0_int8, t) .neqv. expect2)) stop 9
35
36 ! Miscellaneous "obvious" special cases
37 i1 = huge (0_int8)
38 i = huge (0)
39 i8 = huge (0_int64)
40 r = huge (0._real32)
41 d = real (r, real64)
42 if (OUT_OF_RANGE (huge (0_int8), r)) stop 10
43 if (OUT_OF_RANGE (huge (0_int8), d)) stop 11
44 if (OUT_OF_RANGE (huge (0_int8), i)) stop 12
45 if (OUT_OF_RANGE (i1, i)) stop 13
46 if (OUT_OF_RANGE (r, d)) stop 14
47 if (OUT_OF_RANGE (d, r)) stop 15
48 if (OUT_OF_RANGE (i, r)) stop 16
49 if (OUT_OF_RANGE (i8, r)) stop 17
50 if (OUT_OF_RANGE (i, i8)) stop 18
51
52 if (OUT_OF_RANGE (real (i1), i1,f)) stop 19
53 if (OUT_OF_RANGE (real (i,real64), i,f)) stop 20
54
55 if (.not. OUT_OF_RANGE (i, i1)) stop 21
56 if (.not. OUT_OF_RANGE (i8, i)) stop 22
57 if (.not. OUT_OF_RANGE (r, i8)) stop 23
58 if (.not. OUT_OF_RANGE (d, i8)) stop 24
59
60 ! Check passing of optional argument
61 if (any (out_of_range_1 (b, f) .neqv. OUT_OF_RANGE (b, 0_int8, f))) stop 25
62 if (any (out_of_range_1 (b, t) .neqv. OUT_OF_RANGE (b, 0_int8, t))) stop 26
63 if (any (out_of_range_1 (b) .neqv. OUT_OF_RANGE (b, 0_int8) )) stop 27
64
65 if (any (out_of_range_2 (b,i1,f) .neqv. OUT_OF_RANGE (b, 0_int8, f))) stop 28
66 if (any (out_of_range_2 (b,i1,t) .neqv. OUT_OF_RANGE (b, 0_int8, t))) stop 29
67 if (any (out_of_range_2 (b,i1) .neqv. OUT_OF_RANGE (b, 0_int8) )) stop 30
68
69 contains
70
71 elemental logical function out_of_range_1 (x, round)
72 real, intent(in) :: x
73 logical, intent(in), optional :: round
74
75 out_of_range_1 = out_of_range (x, 0_int8, round)
76 end function out_of_range_1
77
78 elemental logical function out_of_range_2 (x, mold, round) result (res)
79 real, intent(in) :: x
80 class(*), intent(in) :: mold
81 logical, intent(in), optional :: round
82
83 select type (mold)
84 type is (integer(int8))
85 res = out_of_range (x, 0_int8, round)
86 class default
87 error stop 99
88 end select
89 end function out_of_range_2
90
91 end