This source file includes following definitions.
- equal
- check
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #define FLOOR_BASED_ROUND round_reference1
28 #define FLOOR_FREE_ROUND round_reference2
29 #include "round.c"
30
31 #include <math.h>
32 #include <float.h>
33 #include <stdbool.h>
34 #include <stdint.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #include "verify.h"
39
40 #ifdef USE_LONG_DOUBLE
41 # error Long double not supported.
42 #elif ! defined USE_FLOAT
43 # include "isnand-nolibm.h"
44 # define ISNAN isnand
45 # define FUNCTION "round"
46 # define DOUBLE_UINT uint64_t
47 # define DOUBLE_BITS 64
48 # define NUM_HIGHBITS 13
49 # define NUM_LOWBITS 4
50 #else
51 # include "isnanf-nolibm.h"
52 # define ISNAN isnanf
53 # define FUNCTION "roundf"
54 # define DOUBLE_UINT uint32_t
55 # define DOUBLE_BITS 32
56 # define NUM_HIGHBITS 12
57 # define NUM_LOWBITS 4
58 #endif
59
60
61 static bool
62 equal (const char *message, DOUBLE x, DOUBLE y0, DOUBLE y1)
63 {
64 if (ISNAN (y0) ? ISNAN (y1) : y0 == y1)
65 return true;
66 else
67 {
68 #if GNULIB_TEST_FPRINTF_POSIX
69 fprintf (stderr, "%s: "FUNCTION"(%g(%a)) = %g(%a) or %g(%a)?\n",
70 message, x, x, y0, y0, y1, y1);
71 #endif
72 return false;
73 }
74 }
75
76
77 static bool
78 check (DOUBLE x)
79 {
80 DOUBLE ref1 = round_reference1 (x);
81 DOUBLE ref2 = round_reference2 (x);
82 DOUBLE result = ROUND (x);
83
84
85 if (!equal ("reference implementations disagree", x, ref1, ref2))
86 exit (EXIT_FAILURE);
87
88
89 return equal ("bad round implementation", x, ref1, result);
90 }
91
92 int
93 main (void)
94 {
95 DOUBLE_UINT highbits, lowbits;
96 int error = 0;
97 for (highbits = 0; highbits < (1 << NUM_HIGHBITS); highbits++)
98 for (lowbits = 0; lowbits < (1 << NUM_LOWBITS); lowbits++)
99 {
100
101
102 union { DOUBLE f; DOUBLE_UINT i; } janus;
103 verify (sizeof janus.f == sizeof janus.i);
104 janus.i = lowbits | (highbits << (DOUBLE_BITS - NUM_HIGHBITS));
105 if (lowbits >> (NUM_LOWBITS - 1))
106 janus.i |= ((DOUBLE_UINT) -1
107 >> (NUM_LOWBITS + NUM_HIGHBITS)
108 << NUM_LOWBITS);
109 if (!check (janus.f))
110 error = true;
111 }
112 return (error ? 1 : 0);
113 }