1 |
|
---|
2 | /*============================================================================
|
---|
3 |
|
---|
4 | This C header file is part of TestFloat, Release 3e, a package of programs for
|
---|
5 | testing the correctness of floating-point arithmetic complying with the IEEE
|
---|
6 | Standard for Floating-Point, by John R. Hauser.
|
---|
7 |
|
---|
8 | Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 The Regents of the
|
---|
9 | University of California. All rights reserved.
|
---|
10 |
|
---|
11 | Redistribution and use in source and binary forms, with or without
|
---|
12 | modification, are permitted provided that the following conditions are met:
|
---|
13 |
|
---|
14 | 1. Redistributions of source code must retain the above copyright notice,
|
---|
15 | this list of conditions, and the following disclaimer.
|
---|
16 |
|
---|
17 | 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
18 | this list of conditions, and the following disclaimer in the documentation
|
---|
19 | and/or other materials provided with the distribution.
|
---|
20 |
|
---|
21 | 3. Neither the name of the University nor the names of its contributors may
|
---|
22 | be used to endorse or promote products derived from this software without
|
---|
23 | specific prior written permission.
|
---|
24 |
|
---|
25 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
---|
26 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
---|
28 | DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
---|
29 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
30 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
32 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
35 |
|
---|
36 | =============================================================================*/
|
---|
37 |
|
---|
38 | #include <stdbool.h>
|
---|
39 | #include <stdint.h>
|
---|
40 | #include <stdio.h>
|
---|
41 | #include <signal.h>
|
---|
42 | #include "uint128.h"
|
---|
43 | #include "softfloat.h"
|
---|
44 |
|
---|
45 | /*----------------------------------------------------------------------------
|
---|
46 | *----------------------------------------------------------------------------*/
|
---|
47 |
|
---|
48 | extern const char *verCases_functionNamePtr;
|
---|
49 | extern uint_fast8_t verCases_roundingPrecision;
|
---|
50 | extern int verCases_roundingCode;
|
---|
51 | extern int verCases_tininessCode;
|
---|
52 | extern bool verCases_usesExact, verCases_exact;
|
---|
53 | extern bool verCases_checkNaNs, verCases_checkInvInts;
|
---|
54 | extern uint_fast32_t verCases_maxErrorCount;
|
---|
55 | extern bool verCases_errorStop;
|
---|
56 |
|
---|
57 | void verCases_writeFunctionName( FILE * );
|
---|
58 |
|
---|
59 | extern volatile sig_atomic_t verCases_stop;
|
---|
60 |
|
---|
61 | extern bool verCases_anyErrors;
|
---|
62 |
|
---|
63 | void verCases_exitWithStatus( void );
|
---|
64 |
|
---|
65 | /*----------------------------------------------------------------------------
|
---|
66 | *----------------------------------------------------------------------------*/
|
---|
67 |
|
---|
68 | #ifdef INLINE
|
---|
69 |
|
---|
70 | #ifdef FLOAT16
|
---|
71 |
|
---|
72 | INLINE bool f16_same( float16_t a, float16_t b )
|
---|
73 | {
|
---|
74 | union { uint16_t ui; float16_t f; } uA, uB;
|
---|
75 | uA.f = a;
|
---|
76 | uB.f = b;
|
---|
77 | return (uA.ui == uB.ui);
|
---|
78 | }
|
---|
79 |
|
---|
80 | INLINE bool f16_isNaN( float16_t a )
|
---|
81 | {
|
---|
82 | union { uint16_t ui; float16_t f; } uA;
|
---|
83 | uA.f = a;
|
---|
84 | return 0x7C00 < (uA.ui & 0x7FFF);
|
---|
85 | }
|
---|
86 |
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | INLINE bool f32_same( float32_t a, float32_t b )
|
---|
90 | {
|
---|
91 | union { uint32_t ui; float32_t f; } uA, uB;
|
---|
92 | uA.f = a;
|
---|
93 | uB.f = b;
|
---|
94 | return (uA.ui == uB.ui);
|
---|
95 | }
|
---|
96 |
|
---|
97 | INLINE bool f32_isNaN( float32_t a )
|
---|
98 | {
|
---|
99 | union { uint32_t ui; float32_t f; } uA;
|
---|
100 | uA.f = a;
|
---|
101 | return 0x7F800000 < (uA.ui & 0x7FFFFFFF);
|
---|
102 | }
|
---|
103 |
|
---|
104 | #ifdef FLOAT64
|
---|
105 |
|
---|
106 | INLINE bool f64_same( float64_t a, float64_t b )
|
---|
107 | {
|
---|
108 | union { uint64_t ui; float64_t f; } uA, uB;
|
---|
109 | uA.f = a;
|
---|
110 | uB.f = b;
|
---|
111 | return (uA.ui == uB.ui);
|
---|
112 | }
|
---|
113 |
|
---|
114 | INLINE bool f64_isNaN( float64_t a )
|
---|
115 | {
|
---|
116 | union { uint64_t ui; float64_t f; } uA;
|
---|
117 | uA.f = a;
|
---|
118 | return
|
---|
119 | UINT64_C( 0x7FF0000000000000 )
|
---|
120 | < (uA.ui & UINT64_C( 0x7FFFFFFFFFFFFFFF ));
|
---|
121 | }
|
---|
122 |
|
---|
123 | #endif
|
---|
124 |
|
---|
125 | #ifdef EXTFLOAT80
|
---|
126 |
|
---|
127 | INLINE bool extF80M_same( const extFloat80_t *aPtr, const extFloat80_t *bPtr )
|
---|
128 | {
|
---|
129 | const struct extFloat80M *aSPtr = (const struct extFloat80M *) aPtr;
|
---|
130 | const struct extFloat80M *bSPtr = (const struct extFloat80M *) bPtr;
|
---|
131 | return
|
---|
132 | (aSPtr->signExp == bSPtr->signExp) && (aSPtr->signif == bSPtr->signif);
|
---|
133 | }
|
---|
134 |
|
---|
135 | INLINE bool extF80M_isNaN( const extFloat80_t *aPtr )
|
---|
136 | {
|
---|
137 | const struct extFloat80M *aSPtr = (const struct extFloat80M *) aPtr;
|
---|
138 | return
|
---|
139 | ((aSPtr->signExp & 0x7FFF) == 0x7FFF)
|
---|
140 | && (aSPtr->signif & UINT64_C( 0x7FFFFFFFFFFFFFFF ));
|
---|
141 | }
|
---|
142 |
|
---|
143 | #endif
|
---|
144 |
|
---|
145 | #ifdef FLOAT128
|
---|
146 |
|
---|
147 | INLINE bool f128M_same( const float128_t *aPtr, const float128_t *bPtr )
|
---|
148 | {
|
---|
149 | const struct uint128 *uiAPtr = (const struct uint128 *) aPtr;
|
---|
150 | const struct uint128 *uiBPtr = (const struct uint128 *) bPtr;
|
---|
151 | return (uiAPtr->v64 == uiBPtr->v64) && (uiAPtr->v0 == uiBPtr->v0);
|
---|
152 | }
|
---|
153 |
|
---|
154 | INLINE bool f128M_isNaN( const float128_t *aPtr )
|
---|
155 | {
|
---|
156 | const struct uint128 *uiAPtr = (const struct uint128 *) aPtr;
|
---|
157 | uint_fast64_t absA64 = uiAPtr->v64 & UINT64_C( 0x7FFFFFFFFFFFFFFF );
|
---|
158 | return
|
---|
159 | (UINT64_C( 0x7FFF000000000000 ) < absA64)
|
---|
160 | || ((absA64 == UINT64_C( 0x7FFF000000000000 )) && uiAPtr->v0);
|
---|
161 | }
|
---|
162 |
|
---|
163 | #endif
|
---|
164 |
|
---|
165 | #else
|
---|
166 |
|
---|
167 | #ifdef FLOAT16
|
---|
168 | bool f16_same( float16_t, float16_t );
|
---|
169 | bool f16_isNaN( float16_t );
|
---|
170 | #endif
|
---|
171 | bool f32_same( float32_t, float32_t );
|
---|
172 | bool f32_isNaN( float32_t );
|
---|
173 | #ifdef FLOAT64
|
---|
174 | bool f64_same( float64_t, float64_t );
|
---|
175 | bool f64_isNaN( float64_t );
|
---|
176 | #endif
|
---|
177 | #ifdef EXTFLOAT80
|
---|
178 | bool extF80M_same( const extFloat80_t *, const extFloat80_t * );
|
---|
179 | bool extF80M_isNaN( const extFloat80_t * );
|
---|
180 | #endif
|
---|
181 | #ifdef FLOAT128
|
---|
182 | bool f128M_same( const float128_t *, const float128_t * );
|
---|
183 | bool f128M_isNaN( const float128_t * );
|
---|
184 | #endif
|
---|
185 |
|
---|
186 | #endif
|
---|
187 |
|
---|
188 | extern uint_fast32_t verCases_tenThousandsCount, verCases_errorCount;
|
---|
189 |
|
---|
190 | void verCases_writeTestsPerformed( int );
|
---|
191 | void verCases_perTenThousand( void );
|
---|
192 | void verCases_writeErrorFound( int );
|
---|
193 |
|
---|