Mercurial > gnulib
annotate tests/test-ieee754-h.c @ 40186:8964917f9574
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Mon, 18 Feb 2019 08:02:49 -0800 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
39759 | 1 /* Test <ieee754.h>. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
39759
diff
changeset
|
2 Copyright 2018-2019 Free Software Foundation, Inc. |
39759 | 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 <https://www.gnu.org/licenses/>. */ | |
16 | |
17 /* Written by Paul Eggert. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <ieee754.h> | |
22 #include <stdio.h> | |
23 | |
24 static struct { | |
25 float x; | |
26 unsigned sign; unsigned exponent; unsigned frac; | |
27 } const float_tests[] = | |
28 { | |
29 {0, 0, 0, 0}, | |
30 {-0.0, 1, 0, 0}, | |
31 {0.1, 0, 0x7b, 0x4ccccd} | |
32 }; | |
33 | |
34 static struct { | |
35 double x; | |
36 unsigned sign; unsigned exponent; unsigned frac_hi; unsigned frac_lo; | |
37 } const double_tests[] = | |
38 { | |
39 {0, 0, 0, 0}, | |
40 {-0.0, 1, 0, 0 }, | |
41 {0.1, 0, 0x3fb, 0x99999, 0x9999999a} | |
42 }; | |
43 | |
44 int | |
45 main (void) | |
46 { | |
47 int i; | |
48 | |
49 for (i = 0; i < sizeof float_tests / sizeof *float_tests; i++) | |
50 { | |
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; | |
59 } | |
60 | |
61 for (i = 0; i < sizeof double_tests / sizeof *double_tests; i++) | |
62 { | |
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; | |
73 } | |
74 | |
75 return 0; | |
76 } |