PR c/29467
[official-gcc.git] / gcc / testsuite / gfortran.dg / nint_2.f90
blob9f2705318fbcbefdbe123d86d84b5fc970ed3dde
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* *-*-mingw* } { "-O0" } { "" } }
8 real(kind=8) :: a
9 integer(kind=8) :: i1, i2
10 real :: b
11 integer :: j1, j2
13 a = nearest(0.5_8,-1.0_8)
14 i2 = nint(nearest(0.5_8,-1.0_8))
15 i1 = nint(a)
16 if (i1 /= 0 .or. i2 /= 0) call abort
18 a = 0.5_8
19 i2 = nint(0.5_8)
20 i1 = nint(a)
21 if (i1 /= 1 .or. i2 /= 1) call abort
23 a = nearest(0.5_8,1.0_8)
24 i2 = nint(nearest(0.5_8,1.0_8))
25 i1 = nint(a)
26 if (i1 /= 1 .or. i2 /= 1) call abort
28 b = nearest(0.5,-1.0)
29 j2 = nint(nearest(0.5,-1.0))
30 j1 = nint(b)
31 if (j1 /= 0 .or. j2 /= 0) call abort
33 b = 0.5
34 j2 = nint(0.5)
35 j1 = nint(b)
36 if (j1 /= 1 .or. j2 /= 1) call abort
38 b = nearest(0.5,1.0)
39 j2 = nint(nearest(0.5,1.0))
40 j1 = nint(b)
41 if (j1 /= 1 .or. j2 /= 1) call abort
43 a = 4503599627370497.0_8
44 i1 = nint(a,kind=8)
45 i2 = nint(4503599627370497.0_8,kind=8)
46 if (i1 /= i2 .or. i1 /= 4503599627370497_8) call abort
48 a = -4503599627370497.0_8
49 i1 = nint(a,kind=8)
50 i2 = nint(-4503599627370497.0_8,kind=8)
51 if (i1 /= i2 .or. i1 /= -4503599627370497_8) call abort
52 end