1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
! { dg-do run }
! { dg-options "-fno-range-check" }
! { dg-add-options ieee }
!
! PR fortran/34192
!
! Test compile-time implementation of NEAREST
!
program test
implicit none
! Single precision
! 0+ > 0
if (nearest(0.0, 1.0) &
<= 0.0) &
STOP 1
! 0++ > 0+
if (nearest(nearest(0.0, 1.0), 1.0) &
<= nearest(0.0, 1.0)) &
STOP 2
! 0+++ > 0++
if (nearest(nearest(nearest(0.0, 1.0), 1.0), 1.0) &
<= nearest(nearest(0.0, 1.0), 1.0)) &
STOP 3
! 0+- = 0
if (nearest(nearest(0.0, 1.0), -1.0) &
/= 0.0) &
STOP 4
! 0++- = 0+
if (nearest(nearest(nearest(0.0, 1.0), 1.0), -1.0) &
/= nearest(0.0, 1.0)) &
STOP 5
! 0++-- = 0
if (nearest(nearest(nearest(nearest(0.0, 1.0), 1.0), -1.0), -1.0) &
/= 0.0) &
STOP 6
! 0- < 0
if (nearest(0.0, -1.0) &
>= 0.0) &
STOP 7
! 0-- < 0+
if (nearest(nearest(0.0, -1.0), -1.0) &
>= nearest(0.0, -1.0)) &
STOP 8
! 0--- < 0--
if (nearest(nearest(nearest(0.0, -1.0), -1.0), -1.0) &
>= nearest(nearest(0.0, -1.0), -1.0)) &
STOP 9
! 0-+ = 0
if (nearest(nearest(0.0, -1.0), 1.0) &
/= 0.0) &
STOP 10
! 0--+ = 0-
if (nearest(nearest(nearest(0.0, -1.0), -1.0), 1.0) &
/= nearest(0.0, -1.0)) &
STOP 11
! 0--++ = 0
if (nearest(nearest(nearest(nearest(0.0, -1.0), -1.0), 1.0), 1.0) &
/= 0.0) &
STOP 12
! 42++ > 42+
if (nearest(nearest(42.0, 1.0), 1.0) &
<= nearest(42.0, 1.0)) &
STOP 13
! 42-- < 42-
if (nearest(nearest(42.0, -1.0), -1.0) &
>= nearest(42.0, -1.0)) &
STOP 14
! 42-+ = 42
if (nearest(nearest(42.0, -1.0), 1.0) &
/= 42.0) &
STOP 15
! 42+- = 42
if (nearest(nearest(42.0, 1.0), -1.0) &
/= 42.0) &
STOP 16
! INF+ = INF
if (nearest(1.0/0.0, 1.0) /= 1.0/0.0) STOP 17
! -INF- = -INF
if (nearest(-1.0/0.0, -1.0) /= -1.0/0.0) STOP 18
! NAN- = NAN
if (.not.isnan(nearest(0.0d0/0.0, 1.0))) STOP 19
! NAN+ = NAN
if (.not.isnan(nearest(0.0d0/0.0, -1.0))) STOP 20
! Double precision
! 0+ > 0
if (nearest(0.0d0, 1.0) &
<= 0.0d0) &
STOP 21
! 0++ > 0+
if (nearest(nearest(0.0d0, 1.0), 1.0) &
<= nearest(0.0d0, 1.0)) &
STOP 22
! 0+++ > 0++
if (nearest(nearest(nearest(0.0d0, 1.0), 1.0), 1.0) &
<= nearest(nearest(0.0d0, 1.0), 1.0)) &
STOP 23
! 0+- = 0
if (nearest(nearest(0.0d0, 1.0), -1.0) &
/= 0.0d0) &
STOP 24
! 0++- = 0+
if (nearest(nearest(nearest(0.0d0, 1.0), 1.0), -1.0) &
/= nearest(0.0d0, 1.0)) &
STOP 25
! 0++-- = 0
if (nearest(nearest(nearest(nearest(0.0d0, 1.0), 1.0), -1.0), -1.0) &
/= 0.0d0) &
STOP 26
! 0- < 0
if (nearest(0.0d0, -1.0) &
>= 0.0d0) &
STOP 27
! 0-- < 0+
if (nearest(nearest(0.0d0, -1.0), -1.0) &
>= nearest(0.0d0, -1.0)) &
STOP 28
! 0--- < 0--
if (nearest(nearest(nearest(0.0d0, -1.0), -1.0), -1.0) &
>= nearest(nearest(0.0d0, -1.0), -1.0)) &
STOP 29
! 0-+ = 0
if (nearest(nearest(0.0d0, -1.0), 1.0) &
/= 0.0d0) &
STOP 30
! 0--+ = 0-
if (nearest(nearest(nearest(0.0d0, -1.0), -1.0), 1.0) &
/= nearest(0.0d0, -1.0)) &
STOP 31
! 0--++ = 0
if (nearest(nearest(nearest(nearest(0.0d0, -1.0), -1.0), 1.0), 1.0) &
/= 0.0d0) &
STOP 32
! 42++ > 42+
if (nearest(nearest(42.0d0, 1.0), 1.0) &
<= nearest(42.0d0, 1.0)) &
STOP 33
! 42-- < 42-
if (nearest(nearest(42.0d0, -1.0), -1.0) &
>= nearest(42.0d0, -1.0)) &
STOP 34
! 42-+ = 42
if (nearest(nearest(42.0d0, -1.0), 1.0) &
/= 42.0d0) &
STOP 35
! 42+- = 42
if (nearest(nearest(42.0d0, 1.0), -1.0) &
/= 42.0d0) &
STOP 36
! INF+ = INF
if (nearest(1.0d0/0.0d0, 1.0) /= 1.0d0/0.0d0) STOP 37
! -INF- = -INF
if (nearest(-1.0d0/0.0d0, -1.0) /= -1.0d0/0.0d0) STOP 38
! NAN- = NAN
if (.not.isnan(nearest(0.0d0/0.0, 1.0))) STOP 39
! NAN+ = NAN
if (.not.isnan(nearest(0.0d0/0.0, -1.0))) STOP 40
end program test
|