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 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 "platform.h"
|
---|
41 | #include "uint128.h"
|
---|
42 | #include "softfloat.h"
|
---|
43 |
|
---|
44 | #ifdef FLOAT16
|
---|
45 |
|
---|
46 | bool f16_same( float16_t a, float16_t b )
|
---|
47 | {
|
---|
48 | union { uint16_t ui; float16_t f; } uA, uB;
|
---|
49 | uA.f = a;
|
---|
50 | uB.f = b;
|
---|
51 | return (uA.ui == uB.ui);
|
---|
52 | }
|
---|
53 |
|
---|
54 | bool f16_isNaN( float16_t a )
|
---|
55 | {
|
---|
56 | union { uint16_t ui; float16_t f; } uA;
|
---|
57 | uA.f = a;
|
---|
58 | return 0x7C00 < (uA.ui & 0x7FFF);
|
---|
59 | }
|
---|
60 |
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | bool f32_same( float32_t a, float32_t b )
|
---|
64 | {
|
---|
65 | union { uint32_t ui; float32_t f; } uA, uB;
|
---|
66 | uA.f = a;
|
---|
67 | uB.f = b;
|
---|
68 | return (uA.ui == uB.ui);
|
---|
69 | }
|
---|
70 |
|
---|
71 | bool f32_isNaN( float32_t a )
|
---|
72 | {
|
---|
73 | union { uint32_t ui; float32_t f; } uA;
|
---|
74 | uA.f = a;
|
---|
75 | return 0x7F800000 < (uA.ui & 0x7FFFFFFF);
|
---|
76 | }
|
---|
77 |
|
---|
78 | #ifdef FLOAT64
|
---|
79 |
|
---|
80 | bool f64_same( float64_t a, float64_t b )
|
---|
81 | {
|
---|
82 | union { uint64_t ui; float64_t f; } uA, uB;
|
---|
83 | uA.f = a;
|
---|
84 | uB.f = b;
|
---|
85 | return (uA.ui == uB.ui);
|
---|
86 | }
|
---|
87 |
|
---|
88 | bool f64_isNaN( float64_t a )
|
---|
89 | {
|
---|
90 | union { uint64_t ui; float64_t f; } uA;
|
---|
91 | uA.f = a;
|
---|
92 | return
|
---|
93 | UINT64_C( 0x7FF0000000000000 )
|
---|
94 | < (uA.ui & UINT64_C( 0x7FFFFFFFFFFFFFFF ));
|
---|
95 | }
|
---|
96 |
|
---|
97 | #endif
|
---|
98 |
|
---|
99 | #ifdef EXTFLOAT80
|
---|
100 |
|
---|
101 | bool extF80M_same( const extFloat80_t *aPtr, const extFloat80_t *bPtr )
|
---|
102 | {
|
---|
103 | const struct extFloat80M *aSPtr = (const struct extFloat80M *) aPtr;
|
---|
104 | const struct extFloat80M *bSPtr = (const struct extFloat80M *) bPtr;
|
---|
105 | return
|
---|
106 | (aSPtr->signExp == bSPtr->signExp) && (aSPtr->signif == bSPtr->signif);
|
---|
107 | }
|
---|
108 |
|
---|
109 | bool extF80M_isNaN( const extFloat80_t *aPtr )
|
---|
110 | {
|
---|
111 | const struct extFloat80M *aSPtr = (const struct extFloat80M *) aPtr;
|
---|
112 | return
|
---|
113 | ((aSPtr->signExp & 0x7FFF) == 0x7FFF)
|
---|
114 | && (aSPtr->signif & UINT64_C( 0x7FFFFFFFFFFFFFFF ));
|
---|
115 | }
|
---|
116 |
|
---|
117 | #endif
|
---|
118 |
|
---|
119 | #ifdef FLOAT128
|
---|
120 |
|
---|
121 | bool f128M_same( const float128_t *aPtr, const float128_t *bPtr )
|
---|
122 | {
|
---|
123 | const struct uint128 *uiAPtr = (const struct uint128 *) aPtr;
|
---|
124 | const struct uint128 *uiBPtr = (const struct uint128 *) bPtr;
|
---|
125 | return (uiAPtr->v64 == uiBPtr->v64) && (uiAPtr->v0 == uiBPtr->v0);
|
---|
126 | }
|
---|
127 |
|
---|
128 | bool f128M_isNaN( const float128_t *aPtr )
|
---|
129 | {
|
---|
130 | const struct uint128 *uiAPtr = (const struct uint128 *) aPtr;
|
---|
131 | uint_fast64_t absA64 = uiAPtr->v64 & UINT64_C( 0x7FFFFFFFFFFFFFFF );
|
---|
132 | return
|
---|
133 | (UINT64_C( 0x7FFF000000000000 ) < absA64)
|
---|
134 | || ((absA64 == UINT64_C( 0x7FFF000000000000 )) && uiAPtr->v0);
|
---|
135 | }
|
---|
136 |
|
---|
137 | #endif
|
---|
138 |
|
---|