annotate tests/test-math.c @ 40231:9b3c79fdfe0b

strtod: fix clash with strtold Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817). * lib/strtod.c (compute_minus_zero, minus_zero): Simplify by remving the macro / external variable, and having just a function. User changed. This avoids the need for an external variable that might clash.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 11 Mar 2019 16:40:29 -0700
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8187
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of <math.h> substitute.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2007-2019 Free Software Foundation, Inc.
8187
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8187
diff changeset
4 This program is free software: you can redistribute it and/or modify
8187
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8187
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8187
diff changeset
7 (at your option) any later version.
8187
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
8187
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <math.h>
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
9850
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
23 #ifndef NAN
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
24 # error NAN should be defined
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
25 choke me
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
26 #endif
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
27
16510
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
28 #ifndef HUGE_VALF
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
29 # error HUGE_VALF should be defined
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
30 choke me
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
31 #endif
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
32
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
33 #ifndef HUGE_VAL
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
34 # error HUGE_VAL should be defined
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
35 choke me
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
36 #endif
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
37
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
38 #ifndef HUGE_VALL
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
39 # error HUGE_VALL should be defined
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
40 choke me
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
41 #endif
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
42
16763
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
43 #ifndef FP_ILOGB0
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
44 # error FP_ILOGB0 should be defined
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
45 choke me
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
46 #endif
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
47
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
48 #ifndef FP_ILOGBNAN
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
49 # error FP_ILOGBNAN should be defined
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
50 choke me
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
51 #endif
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
52
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
53 #include <limits.h>
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
54
16510
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
55 #include "macros.h"
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
56
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
57 #if 0
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
58 /* Check that NAN expands into a constant expression. */
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
59 static float n = NAN;
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
60 #endif
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
61
9856
0148cac24350 Fix test to work on IRIX 6.5 with cc.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
62 /* Compare two numbers with ==.
0148cac24350 Fix test to work on IRIX 6.5 with cc.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
63 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
0148cac24350 Fix test to work on IRIX 6.5 with cc.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
64 'x == x' test. */
0148cac24350 Fix test to work on IRIX 6.5 with cc.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
65 static int
16510
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
66 numeric_equalf (float x, float y)
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
67 {
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
68 return x == y;
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
69 }
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
70 static int
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
71 numeric_equald (double x, double y)
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
72 {
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
73 return x == y;
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
74 }
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
75 static int
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
76 numeric_equall (long double x, long double y)
9856
0148cac24350 Fix test to work on IRIX 6.5 with cc.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
77 {
0148cac24350 Fix test to work on IRIX 6.5 with cc.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
78 return x == y;
0148cac24350 Fix test to work on IRIX 6.5 with cc.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
79 }
0148cac24350 Fix test to work on IRIX 6.5 with cc.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
80
8187
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 int
12197
e45d9bb2233e tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents: 9898
diff changeset
82 main (void)
8187
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 {
9850
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
84 double d = NAN;
9898
02bfc9acab82 Work around Solaris 10 math.h bug.
Eric Blake <ebb9@byu.net>
parents: 9856
diff changeset
85 double zero = 0.0;
16510
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
86 ASSERT (!numeric_equald (d, d));
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
87
9898
02bfc9acab82 Work around Solaris 10 math.h bug.
Eric Blake <ebb9@byu.net>
parents: 9856
diff changeset
88 d = HUGE_VAL;
16510
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
89 ASSERT (numeric_equald (d, 1.0 / zero));
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
90
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
91 ASSERT (numeric_equalf (HUGE_VALF, HUGE_VALF + HUGE_VALF));
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
92
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
93 ASSERT (numeric_equald (HUGE_VAL, HUGE_VAL + HUGE_VAL));
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
94
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
95 ASSERT (numeric_equall (HUGE_VALL, HUGE_VALL + HUGE_VALL));
af909bf507e4 math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
96
16763
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
97 /* Check the value of FP_ILOGB0. */
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
98 ASSERT (FP_ILOGB0 == INT_MIN || FP_ILOGB0 == - INT_MAX);
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
99
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
100 /* Check the value of FP_ILOGBNAN. */
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
101 ASSERT (FP_ILOGBNAN == INT_MIN || FP_ILOGBNAN == INT_MAX);
a56cad559c24 math: Provide FP_ILOGB0 and FP_ILOGBNAN.
Bruno Haible <bruno@clisp.org>
parents: 16510
diff changeset
102
9856
0148cac24350 Fix test to work on IRIX 6.5 with cc.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
103 return 0;
8187
5844c71ffcc0 Tests for module 'math'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 }