Rename isnand.h to isnand-nolibm.h, similarly for isnanf.h.
[gnulib.git] / tests / test-round1.c
1 /* Test of rounding to nearest, breaking ties away from zero.
2    Copyright (C) 2007-2008 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, or (at your option)
7    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, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Ben Pfaff <blp@gnu.org>, 2007.
19    Based heavily on Bruno Haible's test-trunc.c. */
20
21 #include <config.h>
22
23 #include <math.h>
24
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 #include "isnand-nolibm.h"
29 #include "nan.h"
30
31 #define ASSERT(expr) \
32   do                                                                         \
33     {                                                                        \
34       if (!(expr))                                                           \
35         {                                                                    \
36           fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
37           fflush (stderr);                                                   \
38           abort ();                                                          \
39         }                                                                    \
40     }                                                                        \
41   while (0)
42
43 int
44 main ()
45 {
46   /* Zero.  */
47   ASSERT (round (0.0) == 0.0);
48   ASSERT (round (-0.0) == 0.0);
49   /* Positive numbers.  */
50   ASSERT (round (0.3) == 0.0);
51   ASSERT (round (0.5) == 1.0);
52   ASSERT (round (0.7) == 1.0);
53   ASSERT (round (1.0) == 1.0);
54   ASSERT (round (1.5) == 2.0);
55   ASSERT (round (2.5) == 3.0);
56   ASSERT (round (1.999) == 2.0);
57   ASSERT (round (2.0) == 2.0);
58   ASSERT (round (65535.999) == 65536.0);
59   ASSERT (round (65536.0) == 65536.0);
60   ASSERT (round (65536.001) == 65536.0);
61   ASSERT (round (2.341e31) == 2.341e31);
62   /* Negative numbers.  */
63   ASSERT (round (-0.3) == 0.0);
64   ASSERT (round (-0.5) == -1.0);
65   ASSERT (round (-0.7) == -1.0);
66   ASSERT (round (-1.0) == -1.0);
67   ASSERT (round (-1.5) == -2.0);
68   ASSERT (round (-2.5) == -3.0);
69   ASSERT (round (-1.999) == -2.0);
70   ASSERT (round (-2.0) == -2.0);
71   ASSERT (round (-65535.999) == -65536.0);
72   ASSERT (round (-65536.0) == -65536.0);
73   ASSERT (round (-65536.001) == -65536.0);
74   ASSERT (round (-2.341e31) == -2.341e31);
75   /* Infinite numbers.  */
76   ASSERT (round (1.0 / 0.0) == 1.0 / 0.0);
77   ASSERT (round (-1.0 / 0.0) == -1.0 / 0.0);
78   /* NaNs.  */
79   ASSERT (isnand (round (NaNd ())));
80
81   return 0;
82 }