aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/nearest_2.f90
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gfortran.dg/nearest_2.f90')
-rw-r--r--gcc/testsuite/gfortran.dg/nearest_2.f90147
1 files changed, 147 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/nearest_2.f90 b/gcc/testsuite/gfortran.dg/nearest_2.f90
new file mode 100644
index 0000000..4bdad31
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/nearest_2.f90
@@ -0,0 +1,147 @@
+! { dg-do run }
+!
+! 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) &
+ call abort()
+ ! 0++ > 0+
+ if (nearest(nearest(0.0, 1.0), 1.0) &
+ <= nearest(0.0, 1.0)) &
+ call abort()
+ ! 0+++ > 0++
+ if (nearest(nearest(nearest(0.0, 1.0), 1.0), 1.0) &
+ <= nearest(nearest(0.0, 1.0), 1.0)) &
+ call abort()
+ ! 0+- = 0
+ if (nearest(nearest(0.0, 1.0), -1.0) &
+ /= 0.0) &
+ call abort()
+ ! 0++- = 0+
+ if (nearest(nearest(nearest(0.0, 1.0), 1.0), -1.0) &
+ /= nearest(0.0, 1.0)) &
+ call abort()
+ ! 0++-- = 0
+ if (nearest(nearest(nearest(nearest(0.0, 1.0), 1.0), -1.0), -1.0) &
+ /= 0.0) &
+ call abort()
+
+ ! 0- < 0
+ if (nearest(0.0, -1.0) &
+ >= 0.0) &
+ call abort()
+ ! 0-- < 0+
+ if (nearest(nearest(0.0, -1.0), -1.0) &
+ >= nearest(0.0, -1.0)) &
+ call abort()
+ ! 0--- < 0--
+ if (nearest(nearest(nearest(0.0, -1.0), -1.0), -1.0) &
+ >= nearest(nearest(0.0, -1.0), -1.0)) &
+ call abort()
+ ! 0-+ = 0
+ if (nearest(nearest(0.0, -1.0), 1.0) &
+ /= 0.0) &
+ call abort()
+ ! 0--+ = 0-
+ if (nearest(nearest(nearest(0.0, -1.0), -1.0), 1.0) &
+ /= nearest(0.0, -1.0)) &
+ call abort()
+ ! 0--++ = 0
+ if (nearest(nearest(nearest(nearest(0.0, -1.0), -1.0), 1.0), 1.0) &
+ /= 0.0) &
+ call abort()
+
+ ! 42++ > 42+
+ if (nearest(nearest(42.0, 1.0), 1.0) &
+ <= nearest(42.0, 1.0)) &
+ call abort()
+ ! 42-- < 42-
+ if (nearest(nearest(42.0, -1.0), -1.0) &
+ >= nearest(42.0, -1.0)) &
+ call abort()
+ ! 42-+ = 42
+ if (nearest(nearest(42.0, -1.0), 1.0) &
+ /= 42.0) &
+ call abort()
+ ! 42+- = 42
+ if (nearest(nearest(42.0, 1.0), -1.0) &
+ /= 42.0) &
+ call abort()
+
+! Double precision
+
+ ! 0+ > 0
+ if (nearest(0.0d0, 1.0) &
+ <= 0.0d0) &
+ call abort()
+ ! 0++ > 0+
+ if (nearest(nearest(0.0d0, 1.0), 1.0) &
+ <= nearest(0.0d0, 1.0)) &
+ call abort()
+ ! 0+++ > 0++
+ if (nearest(nearest(nearest(0.0d0, 1.0), 1.0), 1.0) &
+ <= nearest(nearest(0.0d0, 1.0), 1.0)) &
+ call abort()
+ ! 0+- = 0
+ if (nearest(nearest(0.0d0, 1.0), -1.0) &
+ /= 0.0d0) &
+ call abort()
+ ! 0++- = 0+
+ if (nearest(nearest(nearest(0.0d0, 1.0), 1.0), -1.0) &
+ /= nearest(0.0d0, 1.0)) &
+ call abort()
+ ! 0++-- = 0
+ if (nearest(nearest(nearest(nearest(0.0d0, 1.0), 1.0), -1.0), -1.0) &
+ /= 0.0d0) &
+ call abort()
+
+ ! 0- < 0
+ if (nearest(0.0d0, -1.0) &
+ >= 0.0d0) &
+ call abort()
+ ! 0-- < 0+
+ if (nearest(nearest(0.0d0, -1.0), -1.0) &
+ >= nearest(0.0d0, -1.0)) &
+ call abort()
+ ! 0--- < 0--
+ if (nearest(nearest(nearest(0.0d0, -1.0), -1.0), -1.0) &
+ >= nearest(nearest(0.0d0, -1.0), -1.0)) &
+ call abort()
+ ! 0-+ = 0
+ if (nearest(nearest(0.0d0, -1.0), 1.0) &
+ /= 0.0d0) &
+ call abort()
+ ! 0--+ = 0-
+ if (nearest(nearest(nearest(0.0d0, -1.0), -1.0), 1.0) &
+ /= nearest(0.0d0, -1.0)) &
+ call abort()
+ ! 0--++ = 0
+ if (nearest(nearest(nearest(nearest(0.0d0, -1.0), -1.0), 1.0), 1.0) &
+ /= 0.0d0) &
+ call abort()
+
+ ! 42++ > 42+
+ if (nearest(nearest(42.0d0, 1.0), 1.0) &
+ <= nearest(42.0d0, 1.0)) &
+ call abort()
+ ! 42-- < 42-
+ if (nearest(nearest(42.0d0, -1.0), -1.0) &
+ >= nearest(42.0d0, -1.0)) &
+ call abort()
+ ! 42-+ = 42
+ if (nearest(nearest(42.0d0, -1.0), 1.0) &
+ /= 42.0d0) &
+ call abort()
+ ! 42+- = 42
+ if (nearest(nearest(42.0d0, 1.0), -1.0) &
+ /= 42.0d0) &
+ call abort()
+end program test