maint: update all copyright year number ranges
[gnulib.git] / tests / test-rint.c
1 /* Test of rint() function.
2    Copyright (C) 2010-2012 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010.  */
18
19 #include <config.h>
20
21 #include <math.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (rint, double, (double));
25
26 #include <float.h>
27 #include <stdio.h>
28
29 #include "isnand-nolibm.h"
30 #include "minus-zero.h"
31 #include "infinity.h"
32 #include "nan.h"
33 #include "macros.h"
34
35 int
36 main ()
37 {
38   /* Consider the current rounding mode, cf.
39      <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/float.h.html>  */
40   if (FLT_ROUNDS == 1)
41     {
42       /* The current rounding mode is round-to-nearest
43          (the default in IEEE 754).  */
44
45       /* Zero.  */
46       ASSERT (rint (0.0) == 0.0);
47       ASSERT (rint (minus_zerod) == 0.0);
48       /* Positive numbers.  */
49       ASSERT (rint (0.3) == 0.0);
50       ASSERT (rint (0.5) == 0.0); /* unlike round() */
51       ASSERT (rint (0.7) == 1.0);
52       ASSERT (rint (1.0) == 1.0);
53       ASSERT (rint (1.5) == 2.0);
54       ASSERT (rint (1.999) == 2.0);
55       ASSERT (rint (2.0) == 2.0);
56       ASSERT (rint (2.1) == 2.0);
57       ASSERT (rint (2.5) == 2.0); /* unlike round() */
58       ASSERT (rint (2.7) == 3.0);
59       ASSERT (rint (65535.999) == 65536.0);
60       ASSERT (rint (65536.0) == 65536.0);
61       ASSERT (rint (65536.001) == 65536.0);
62       ASSERT (rint (2.341e31) == 2.341e31);
63       /* Negative numbers.  */
64       ASSERT (rint (-0.3) == 0.0);
65       ASSERT (rint (-0.5) == 0.0); /* unlike round() */
66       ASSERT (rint (-0.7) == -1.0);
67       ASSERT (rint (-1.0) == -1.0);
68       ASSERT (rint (-1.5) == -2.0);
69       ASSERT (rint (-1.999) == -2.0);
70       ASSERT (rint (-2.0) == -2.0);
71       ASSERT (rint (-2.1) == -2.0);
72       ASSERT (rint (-2.5) == -2.0); /* unlike round() */
73       ASSERT (rint (-2.7) == -3.0);
74       ASSERT (rint (-65535.999) == -65536.0);
75       ASSERT (rint (-65536.0) == -65536.0);
76       ASSERT (rint (-65536.001) == -65536.0);
77       ASSERT (rint (-2.341e31) == -2.341e31);
78       /* Infinite numbers.  */
79       ASSERT (rint (Infinityd ()) == Infinityd ());
80       ASSERT (rint (- Infinityd ()) == - Infinityd ());
81       /* NaNs.  */
82       ASSERT (isnand (rint (NaNd ())));
83
84       return 0;
85     }
86   else
87     {
88       fputs ("Skipping test: non-standard rounding mode\n", stderr);
89       return 77;
90     }
91 }