Support compiling without -loldnames on native Windows.
[gnulib.git] / tests / test-ieee754-h.c
blob282cbd05714147b69cb562477419c00a8b837b88
1 /* Test <ieee754.h>.
2 Copyright 2018-2020 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Paul Eggert. */
19 #include <config.h>
21 #include <ieee754.h>
22 #include <stdio.h>
24 static struct {
25 float x;
26 unsigned sign; unsigned exponent; unsigned frac;
27 } const float_tests[] =
29 {0, 0, 0, 0},
30 {-0.0, 1, 0, 0},
31 {0.1, 0, 0x7b, 0x4ccccd}
34 static struct {
35 double x;
36 unsigned sign; unsigned exponent; unsigned frac_hi; unsigned frac_lo;
37 } const double_tests[] =
39 {0, 0, 0, 0},
40 {-0.0, 1, 0, 0 },
41 {0.1, 0, 0x3fb, 0x99999, 0x9999999a}
44 int
45 main (void)
47 int i;
49 for (i = 0; i < sizeof float_tests / sizeof *float_tests; i++)
51 union ieee754_float u;
52 u.f = float_tests[i].x;
53 if (float_tests[i].sign != u.ieee.negative)
54 return 1;
55 if (float_tests[i].exponent != u.ieee.exponent)
56 return 2;
57 if (float_tests[i].frac != u.ieee.mantissa)
58 return 3;
61 for (i = 0; i < sizeof double_tests / sizeof *double_tests; i++)
63 union ieee754_double u;
64 u.d = double_tests[i].x;
65 if (double_tests[i].sign != u.ieee.negative)
66 return 4;
67 if (double_tests[i].exponent != u.ieee.exponent)
68 return 5;
69 if (double_tests[i].frac_hi != u.ieee.mantissa0)
70 return 6;
71 if (double_tests[i].frac_lo != u.ieee.mantissa1)
72 return 7;
75 return 0;