VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/testfloat/source/verCases_inline.c@ 106842

Last change on this file since 106842 was 94551, checked in by vboxsync, 3 years ago

libs/softfloat: Copied TestFloat-3e from vendor branch and to testfloat subdir. bugref:9898

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1
2/*============================================================================
3
4This C header file is part of TestFloat, Release 3e, a package of programs for
5testing the correctness of floating-point arithmetic complying with the IEEE
6Standard for Floating-Point, by John R. Hauser.
7
8Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
9University of California. All rights reserved.
10
11Redistribution and use in source and binary forms, with or without
12modification, 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
25THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
26EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
28DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
29DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32ON 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
34SOFTWARE, 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
46bool 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
54bool 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
63bool 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
71bool 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
80bool 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
88bool 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
101bool 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
109bool 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
121bool 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
128bool 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
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette