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
26namespace astcenc
27{
28
29#if (ASTCENC_F16C == 0) && (ASTCENC_NEON == 0)
30
31/** @brief Test normal numbers. */
32TEST(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. */
39TEST(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. */
46TEST(softfloat, FP16Zero)
47{
48	float result = sf16_to_float(0x0000);
49	EXPECT_EQ(result, 0.0f);
50}
51
52/** @brief Test infinity. */
53TEST(softfloat, FP16Infinity)
54{
55	float result = sf16_to_float((31 << 10) + 0);
56	EXPECT_TRUE(std::isinf(result));
57}
58
59/** @brief Test NaN. */
60TEST(softfloat, FP16NaN)
61{
62	float result = sf16_to_float(0xFFFF);
63	EXPECT_TRUE(std::isnan(result));
64}
65
66#endif
67
68}
69