PR middle-end/77674
[official-gcc.git] / gcc / testsuite / gfortran.dg / nint_2.f90
blob0727136dfc9a8701281e5130beb33cb8e685b5e9
1 ! Test that NINT gives right results even in corner cases
3 ! PR 31202
4 ! http://gcc.gnu.org/ml/fortran/2005-04/msg00139.html
6 ! { dg-do run }
7 ! { dg-xfail-run-if "PR 33271, math library bug" { powerpc-ibm-aix* powerpc-*-linux* powerpc64-*-linux* *-*-mingw* } { "-O0" } { "" } }
8 ! Note that this doesn't fail on powerpc64le-*-linux*.
9 real(kind=8) :: a
10 integer(kind=8) :: i1, i2
11 real :: b
12 integer :: j1, j2
14 a = nearest(0.5_8,-1.0_8)
15 i2 = nint(nearest(0.5_8,-1.0_8))
16 i1 = nint(a)
17 if (i1 /= 0 .or. i2 /= 0) call abort
19 a = 0.5_8
20 i2 = nint(0.5_8)
21 i1 = nint(a)
22 if (i1 /= 1 .or. i2 /= 1) call abort
24 a = nearest(0.5_8,1.0_8)
25 i2 = nint(nearest(0.5_8,1.0_8))
26 i1 = nint(a)
27 if (i1 /= 1 .or. i2 /= 1) call abort
29 b = nearest(0.5,-1.0)
30 j2 = nint(nearest(0.5,-1.0))
31 j1 = nint(b)
32 if (j1 /= 0 .or. j2 /= 0) call abort
34 b = 0.5
35 j2 = nint(0.5)
36 j1 = nint(b)
37 if (j1 /= 1 .or. j2 /= 1) call abort
39 b = nearest(0.5,1.0)
40 j2 = nint(nearest(0.5,1.0))
41 j1 = nint(b)
42 if (j1 /= 1 .or. j2 /= 1) call abort
44 a = 4503599627370497.0_8
45 i1 = nint(a,kind=8)
46 i2 = nint(4503599627370497.0_8,kind=8)
47 if (i1 /= i2 .or. i1 /= 4503599627370497_8) call abort
49 a = -4503599627370497.0_8
50 i1 = nint(a,kind=8)
51 i2 = nint(-4503599627370497.0_8,kind=8)
52 if (i1 /= i2 .or. i1 /= -4503599627370497_8) call abort
53 end