Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / __support / FPUtil / dyadic_float_test.cpp
blob8fafa767ae38e34520ae2a310649ca2ece0851c5
1 //===-- Unittests for the DyadicFloat class -------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/__support/FPUtil/dyadic_float.h"
10 #include "src/__support/UInt.h"
11 #include "test/UnitTest/FPMatcher.h"
12 #include "test/UnitTest/Test.h"
13 #include "utils/MPFRWrapper/MPFRUtils.h"
15 using Float128 = LIBC_NAMESPACE::fputil::DyadicFloat<128>;
16 using Float192 = LIBC_NAMESPACE::fputil::DyadicFloat<192>;
17 using Float256 = LIBC_NAMESPACE::fputil::DyadicFloat<256>;
19 TEST(LlvmLibcDyadicFloatTest, BasicConversions) {
20 Float128 x(/*sign*/ false, /*exponent*/ 0,
21 /*mantissa*/ Float128::MantissaType(1));
22 volatile float xf = float(x);
23 volatile double xd = double(x);
24 ASSERT_FP_EQ(1.0f, xf);
25 ASSERT_FP_EQ(1.0, xd);
27 Float128 y(0x1.0p-53);
28 volatile float yf = float(y);
29 volatile double yd = double(y);
30 ASSERT_FP_EQ(0x1.0p-53f, yf);
31 ASSERT_FP_EQ(0x1.0p-53, yd);
33 Float128 z = quick_add(x, y);
35 EXPECT_FP_EQ_ALL_ROUNDING(xf + yf, float(z));
36 EXPECT_FP_EQ_ALL_ROUNDING(xd + yd, double(z));
39 TEST(LlvmLibcDyadicFloatTest, QuickAdd) {
40 Float192 x(/*sign*/ false, /*exponent*/ 0,
41 /*mantissa*/ Float192::MantissaType(0x123456));
42 volatile double xd = double(x);
43 ASSERT_FP_EQ(0x1.23456p20, xd);
45 Float192 y(0x1.abcdefp-20);
46 volatile double yd = double(y);
47 ASSERT_FP_EQ(0x1.abcdefp-20, yd);
49 Float192 z = quick_add(x, y);
51 EXPECT_FP_EQ_ALL_ROUNDING(xd + yd, (volatile double)(z));
54 TEST(LlvmLibcDyadicFloatTest, QuickMul) {
55 Float256 x(/*sign*/ false, /*exponent*/ 0,
56 /*mantissa*/ Float256::MantissaType(0x123456));
57 volatile double xd = double(x);
58 ASSERT_FP_EQ(0x1.23456p20, xd);
60 Float256 y(0x1.abcdefp-25);
61 volatile double yd = double(y);
62 ASSERT_FP_EQ(0x1.abcdefp-25, yd);
64 Float256 z = quick_mul(x, y);
66 EXPECT_FP_EQ_ALL_ROUNDING(xd * yd, double(z));