1 //===-- Utility class to test fixed-point abs -------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "test/UnitTest/Test.h"
11 #include "src/__support/fixed_point/fx_rep.h"
13 template <typename T
> class AbsTest
: public LIBC_NAMESPACE::testing::Test
{
15 using FXRep
= LIBC_NAMESPACE::fixed_point::FXRep
<T
>;
16 static constexpr T zero
= FXRep::ZERO();
17 static constexpr T min
= FXRep::MIN();
18 static constexpr T max
= FXRep::MAX();
19 static constexpr T half
= static_cast<T
>(0.5);
20 static constexpr T neg_half
= static_cast<T
>(-0.5);
23 typedef T (*AbsFunc
)(T
);
25 void testSpecialNumbers(AbsFunc func
) {
26 EXPECT_EQ(zero
, func(zero
));
27 EXPECT_EQ(max
, func(min
));
28 EXPECT_EQ(max
, func(max
));
29 EXPECT_EQ(half
, func(half
));
30 EXPECT_EQ(half
, func(neg_half
));
34 #define LIST_ABS_TESTS(T, func) \
35 using LlvmLibcAbsTest = AbsTest<T>; \
36 TEST_F(LlvmLibcAbsTest, SpecialNumbers) { testSpecialNumbers(&func); } \
37 static_assert(true, "Require semicolon.")