1! RUN: %S/test_folding.sh %s %t %f18 2 3! Test intrinsic operation folding 4 5module m 6! Check logical intrinsic operation folding 7 logical, parameter :: test_not1 = .NOT..false. 8 logical, parameter :: test_not2 = .NOT..NOT..true. 9 10 logical, parameter :: test_parentheses1 = .NOT.(.false.) 11 logical, parameter :: test_parentheses2 = .NOT..NOT.(.true.) 12 13 logical, parameter :: test_and1 = .true..AND..true. 14 logical, parameter :: test_and2 = .NOT.(.false..AND..true.) 15 logical, parameter :: test_and3 = .NOT.(.false..AND..false.) 16 logical, parameter :: test_and4 = .NOT.(.true..AND..false.) 17 18 logical, parameter :: test_or1 = .true..OR..true. 19 logical, parameter :: test_or2 = .false..OR..true. 20 logical, parameter :: test_or3 = .NOT.(.false..OR..false.) 21 logical, parameter :: test_or4 = .true..OR..false. 22 23 logical, parameter :: test_eqv1 = .false..EQV..false. 24 logical, parameter :: test_eqv2 = .true..EQV..true. 25 logical, parameter :: test_eqv3 = .NOT.(.false..EQV..true.) 26 logical, parameter :: test_eqv4 = .NOT.(.true..EQV..false.) 27 28 logical, parameter :: test_neqv1 = .true..NEQV..false. 29 logical, parameter :: test_neqv2 = .false..NEQV..true. 30 logical, parameter :: test_neqv3 = .NOT.(.false..NEQV..false.) 31 logical, parameter :: test_neqv4 = .NOT.(.true..NEQV..true.) 32 33! Check integer intrinsic operator folding 34 35! Check integer relational intrinsic operation folding 36 logical, parameter :: test_le_i1 = 1.LE.2 37 logical, parameter :: test_le_i2 = .NOT.(2.LE.1) 38 logical, parameter :: test_le_i3 = 2.LE.2 39 logical, parameter :: test_le_i4 = -1.LE.2 40 logical, parameter :: test_le_i5 = .NOT.(-2.LE.-3) 41 42 logical, parameter :: test_lt_i1 = 1.LT.2 43 logical, parameter :: test_lt_i2 = .NOT.(2.LT.1) 44 logical, parameter :: test_lt_i3 = .NOT.(2.LT.2) 45 logical, parameter :: test_lt_i4 = -1.LT.2 46 logical, parameter :: test_lt_i5 = .NOT.(-2.LT.-3) 47 48 logical, parameter :: test_ge_i1 = .NOT.(1.GE.2) 49 logical, parameter :: test_ge_i2 = 2.GE.1 50 logical, parameter :: test_ge_i3 = 2.GE.2 51 logical, parameter :: test_ge_i4 = .NOT.(-1.GE.2) 52 logical, parameter :: test_ge_i5 = -2.GE.-3 53 54 logical, parameter :: test_gt_i1 = .NOT.(1.GT.2) 55 logical, parameter :: test_gt_i2 = 2.GT.1 56 logical, parameter :: test_gt_i3 = .NOT.(2.GT.2) 57 logical, parameter :: test_gt_i4 = .NOT.(-1.GT.2) 58 logical, parameter :: test_gt_i5 = -2.GT.-3 59 60 logical, parameter :: test_eq_i1 = 2.EQ.2 61 logical, parameter :: test_eq_i2 = .NOT.(-2.EQ.2) 62 63 logical, parameter :: test_ne_i1 =.NOT.(2.NE.2) 64 logical, parameter :: test_ne_i2 = -2.NE.2 65 66! Check conversions 67 logical, parameter :: test_cmplx1 = cmplx((1._4, -1._4)).EQ.((1._4, -1._4)) 68 logical, parameter :: test_cmplx2 = cmplx((1._4, -1._4), 8).EQ.((1._8, -1._8)) 69 logical, parameter :: test_cmplx3 = cmplx(1._4, -1._4).EQ.((1._4, -1._4)) 70 logical, parameter :: test_cmplx4 = cmplx(1._4, -1._4, 8).EQ.((1._8, -1._8)) 71 logical, parameter :: test_cmplx5 = cmplx(1._4).EQ.((1._4, 0._4)) 72 logical, parameter :: test_cmplx6 = cmplx(1._4, kind=8).EQ.((1._8, 0._8)) 73 74! Check integer intrinsic operation folding 75 logical, parameter :: test_unaryminus_i = (-(-1)).EQ.1 76 logical, parameter :: test_unaryplus_i = (+1).EQ.1 77 78 logical, parameter :: test_plus_i1 = (1+1).EQ.2 79 logical, parameter :: test_plus_i2 = ((-3)+1).EQ.-2 80 81 logical, parameter :: test_minus_i1 = (1-1).EQ.0 82 logical, parameter :: test_minus_i2 = (1-(-1)).EQ.2 83 84 logical, parameter :: test_multiply_i1 = (2*2).EQ.4 85 logical, parameter :: test_multiply_i2 = (0*1).EQ.0 86 logical, parameter :: test_multiply_i3= ((-3)*2).EQ.(-6) 87 88 logical, parameter :: test_divide_i1 = (5/3).EQ.(1) 89 logical, parameter :: test_divide_i2 = (6/3).EQ.(2) 90 logical, parameter :: test_divide_i3 = ((-7)/2).EQ.(-3) 91 logical, parameter :: test_divide_i4 = (0/127).EQ.(0) 92 93 logical, parameter :: test_pow1 = (2**0).EQ.(1) 94 logical, parameter :: test_pow2 = (1**100).EQ.(1) 95 logical, parameter :: test_pow3 = (2**4).EQ.(16) 96 logical, parameter :: test_pow4 = (7**5).EQ.(16807) 97 logical, parameter :: test_pow5 = kind(real(1., kind=8)**cmplx(1., kind=4)).EQ.(8) 98 logical, parameter :: test_pow6 = kind(cmplx(1., kind=4)**real(1., kind=8)).EQ.(8) 99 100 ! test MIN and MAX 101 real, parameter :: x1 = -35., x2= -35.05, x3=0., x4=35.05, x5=35. 102 real, parameter :: res_max_r = max(x1, x2, x3, x4, x5) 103 real, parameter :: res_min_r = min(x1, x2, x3, x4, x5) 104 logical, parameter :: test_max_r = res_max_r.EQ.x4 105 logical, parameter :: test_min_r = res_min_r.EQ.x2 106 107 logical, parameter :: test_min_i = min(-3, 3).EQ.-3 108 logical, parameter :: test_max_i = max(-3, 3).EQ.3 109 integer, parameter :: i1 = 35, i2= 36, i3=0, i4=-35, i5=-36 110 integer, parameter :: res_max_i = max(i1, i2, i3, i4, i5) 111 integer, parameter :: res_min_i = min(i1, i2, i3, i4, i5) 112 logical, parameter :: test_max_i2 = res_max_i.EQ.i2 113 logical, parameter :: test_min_i2 = res_min_i.EQ.i5 114 115 character(*), parameter :: c1 = "elephant", c2="elevator" 116 character(*), parameter :: c3 = "excalibur", c4="z", c5="epsilon" 117 character(*), parameter :: res_max_c = max(c1, c2, c3, c4, c5) 118 character(*), parameter :: res_min_c = min(c1, c2, c3, c4, c5) 119 ! length of result is length of longest arguments! 120 character(len(c3)), parameter :: exp_min = c1 121 character(len(c3)), parameter :: exp_max = c4 122 logical, parameter :: test_max_c_1 = res_max_c.EQ.exp_max 123 logical, parameter :: test_max_c_2 = res_max_c.NE.c4 124 logical, parameter :: test_max_c_3 = len(res_max_c).EQ.len(c3) 125 logical, parameter :: test_min_c_1 = res_min_c.NE.c1 126 logical, parameter :: test_min_c_2 = res_min_c.EQ.exp_min 127 logical, parameter :: test_min_c_3 = len(res_min_c).EQ.len(c3) 128 129 integer, parameter :: x1a(*) = [1, 12, 3, 14] 130 integer, parameter :: x2a(*) = [11, 2, 13, 4] 131 logical, parameter :: test_max_a1 = all(max(x1a, x2a).EQ.[11, 12, 13, 14]) 132 logical, parameter :: test_min_a1 = all(min(x1a, x2a).EQ.[1, 2, 3, 4]) 133 134end module 135