Merge tag 'snapshot-start' into stable
[gnulib.git] / tests / test-math.c
1 /* Test of <math.h> substitute.
2    Copyright (C) 2007-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>, 2007.  */
18
19 #include <config.h>
20
21 #include <math.h>
22
23 #ifndef NAN
24 # error NAN should be defined
25 choke me
26 #endif
27
28 #ifndef HUGE_VALF
29 # error HUGE_VALF should be defined
30 choke me
31 #endif
32
33 #ifndef HUGE_VAL
34 # error HUGE_VAL should be defined
35 choke me
36 #endif
37
38 #ifndef HUGE_VALL
39 # error HUGE_VALL should be defined
40 choke me
41 #endif
42
43 #include "macros.h"
44
45 #if 0
46 /* Check that NAN expands into a constant expression.  */
47 static float n = NAN;
48 #endif
49
50 /* Compare two numbers with ==.
51    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
52    'x == x' test.  */
53 static int
54 numeric_equalf (float x, float y)
55 {
56   return x == y;
57 }
58 static int
59 numeric_equald (double x, double y)
60 {
61   return x == y;
62 }
63 static int
64 numeric_equall (long double x, long double y)
65 {
66   return x == y;
67 }
68
69 int
70 main (void)
71 {
72   double d = NAN;
73   double zero = 0.0;
74   ASSERT (!numeric_equald (d, d));
75
76   d = HUGE_VAL;
77   ASSERT (numeric_equald (d, 1.0 / zero));
78
79   ASSERT (numeric_equalf (HUGE_VALF, HUGE_VALF + HUGE_VALF));
80
81   ASSERT (numeric_equald (HUGE_VAL, HUGE_VAL + HUGE_VAL));
82
83   ASSERT (numeric_equall (HUGE_VALL, HUGE_VALL + HUGE_VALL));
84
85   return 0;
86 }