1 // SPDX-License-Identifier: Apache-2.0
2 // ----------------------------------------------------------------------------
3 // Copyright 2021 Arm Limited
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 // use this file except in compliance with the License. You may obtain a copy
7 // of the License at:
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 // License for the specific language governing permissions and limitations
15 // under the License.
16 // ----------------------------------------------------------------------------
17
18 /**
19 * @brief Unit tests for the software half-float library.
20 */
21
22 #include "gtest/gtest.h"
23
24 #include "../astcenc_internal.h"
25
26 namespace astcenc
27 {
28
29 #if (ASTCENC_F16C == 0) && (ASTCENC_NEON == 0)
30
31 /** @brief Test normal numbers. */
TEST(softfloat,FP16NormalNumbers)32 TEST(softfloat, FP16NormalNumbers)
33 {
34 float result = sf16_to_float((15 << 10) + 1);
35 EXPECT_NEAR(result, 1.00098f, 0.00005f);
36 }
37
38 /** @brief Test denormal numbers. */
TEST(softfloat,FP16DenormalNumbers)39 TEST(softfloat, FP16DenormalNumbers)
40 {
41 float result = sf16_to_float((0 << 10) + 1);
42 EXPECT_NEAR(result, 5.96046e-08f, 0.00005f);
43 }
44
45 /** @brief Test zero. */
TEST(softfloat,FP16Zero)46 TEST(softfloat, FP16Zero)
47 {
48 float result = sf16_to_float(0x0000);
49 EXPECT_EQ(result, 0.0f);
50 }
51
52 /** @brief Test infinity. */
TEST(softfloat,FP16Infinity)53 TEST(softfloat, FP16Infinity)
54 {
55 float result = sf16_to_float((31 << 10) + 0);
56 EXPECT_TRUE(std::isinf(result));
57 }
58
59 /** @brief Test NaN. */
TEST(softfloat,FP16NaN)60 TEST(softfloat, FP16NaN)
61 {
62 float result = sf16_to_float(0xFFFF);
63 EXPECT_TRUE(std::isnan(result));
64 }
65
66 #endif
67
68 }
69