aboutsummaryrefslogtreecommitdiff
path: root/libc/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'libc/test/src')
-rw-r--r--libc/test/src/__support/integer_literals_test.cpp21
-rw-r--r--libc/test/src/__support/math_extras_test.cpp57
-rw-r--r--libc/test/src/__support/uint_test.cpp192
-rw-r--r--libc/test/src/math/CMakeLists.txt15
-rw-r--r--libc/test/src/math/exhaustive/CMakeLists.txt15
-rw-r--r--libc/test/src/math/exhaustive/exp2m1f_test.cpp33
-rw-r--r--libc/test/src/math/exp2m1f_test.cpp66
-rw-r--r--libc/test/src/math/smoke/CMakeLists.txt11
-rw-r--r--libc/test/src/math/smoke/exp2m1f_test.cpp63
9 files changed, 472 insertions, 1 deletions
diff --git a/libc/test/src/__support/integer_literals_test.cpp b/libc/test/src/__support/integer_literals_test.cpp
index 5298cf3..cbc906a 100644
--- a/libc/test/src/__support/integer_literals_test.cpp
+++ b/libc/test/src/__support/integer_literals_test.cpp
@@ -133,3 +133,24 @@ TEST(LlvmLibcIntegerLiteralTest, u256) {
U256_MAX,
0xFFFFFFFF'FFFFFFFF'FFFFFFFF'FFFFFFFF'FFFFFFFF'FFFFFFFF'FFFFFFFF'FFFFFFFF_u256);
}
+
+TEST(LlvmLibcIntegerLiteralTest, parse_bigint) {
+ using T = LIBC_NAMESPACE::Int<128>;
+ struct {
+ const char *str;
+ T expected;
+ } constexpr TEST_CASES[] = {
+ {"0", 0}, {"-1", -1}, {"+1", 1}, {"-0xFF", -255}, {"-0b11", -3},
+ };
+ for (auto tc : TEST_CASES) {
+ T actual = LIBC_NAMESPACE::parse_bigint<T>(tc.str);
+ EXPECT_EQ(actual, tc.expected);
+ }
+}
+
+TEST(LlvmLibcIntegerLiteralTest, parse_bigint_invalid) {
+ using T = LIBC_NAMESPACE::Int<128>;
+ const T expected; // default construction
+ EXPECT_EQ(LIBC_NAMESPACE::parse_bigint<T>(nullptr), expected);
+ EXPECT_EQ(LIBC_NAMESPACE::parse_bigint<T>(""), expected);
+}
diff --git a/libc/test/src/__support/math_extras_test.cpp b/libc/test/src/__support/math_extras_test.cpp
index e88b3e1..401e631e 100644
--- a/libc/test/src/__support/math_extras_test.cpp
+++ b/libc/test/src/__support/math_extras_test.cpp
@@ -101,4 +101,61 @@ TYPED_TEST(LlvmLibcBitTest, CountZeros, UnsignedTypesNoBigInt) {
EXPECT_EQ(count_zeros<T>(cpp::numeric_limits<T>::max() >> i), i);
}
+using UnsignedTypes = testing::TypeList<
+#if defined(__SIZEOF_INT128__)
+ __uint128_t,
+#endif
+ unsigned char, unsigned short, unsigned int, unsigned long,
+ unsigned long long>;
+
+TYPED_TEST(LlvmLibcBlockMathExtrasTest, add_overflow, UnsignedTypes) {
+ constexpr T ZERO = cpp::numeric_limits<T>::min();
+ constexpr T ONE(1);
+ constexpr T MAX = cpp::numeric_limits<T>::max();
+ constexpr T BEFORE_MAX = MAX - 1;
+
+ const struct {
+ T lhs;
+ T rhs;
+ T sum;
+ bool carry;
+ } TESTS[] = {
+ {ZERO, ONE, ONE, false}, // 0x00 + 0x01 = 0x01
+ {BEFORE_MAX, ONE, MAX, false}, // 0xFE + 0x01 = 0xFF
+ {MAX, ONE, ZERO, true}, // 0xFF + 0x01 = 0x00 (carry)
+ {MAX, MAX, BEFORE_MAX, true}, // 0xFF + 0xFF = 0xFE (carry)
+ };
+ for (auto tc : TESTS) {
+ T sum;
+ bool carry = add_overflow<T>(tc.lhs, tc.rhs, sum);
+ EXPECT_EQ(sum, tc.sum);
+ EXPECT_EQ(carry, tc.carry);
+ }
+}
+
+TYPED_TEST(LlvmLibcBlockMathExtrasTest, sub_overflow, UnsignedTypes) {
+ constexpr T ZERO = cpp::numeric_limits<T>::min();
+ constexpr T ONE(1);
+ constexpr T MAX = cpp::numeric_limits<T>::max();
+ constexpr T BEFORE_MAX = MAX - 1;
+
+ const struct {
+ T lhs;
+ T rhs;
+ T sub;
+ bool carry;
+ } TESTS[] = {
+ {ONE, ZERO, ONE, false}, // 0x01 - 0x00 = 0x01
+ {MAX, MAX, ZERO, false}, // 0xFF - 0xFF = 0x00
+ {ZERO, ONE, MAX, true}, // 0x00 - 0x01 = 0xFF (carry)
+ {BEFORE_MAX, MAX, MAX, true}, // 0xFE - 0xFF = 0xFF (carry)
+ };
+ for (auto tc : TESTS) {
+ T sub;
+ bool carry = sub_overflow<T>(tc.lhs, tc.rhs, sub);
+ EXPECT_EQ(sub, tc.sub);
+ EXPECT_EQ(carry, tc.carry);
+ }
+}
+
} // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/__support/uint_test.cpp b/libc/test/src/__support/uint_test.cpp
index 5764324..5696e54 100644
--- a/libc/test/src/__support/uint_test.cpp
+++ b/libc/test/src/__support/uint_test.cpp
@@ -8,6 +8,7 @@
#include "src/__support/CPP/optional.h"
#include "src/__support/UInt.h"
+#include "src/__support/integer_literals.h" // parse_unsigned_bigint
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
#include "include/llvm-libc-macros/math-macros.h" // HUGE_VALF, HUGE_VALF
@@ -15,6 +16,195 @@
namespace LIBC_NAMESPACE {
+enum Value { ZERO, ONE, TWO, MIN, MAX };
+
+template <typename T> auto create(Value value) {
+ switch (value) {
+ case ZERO:
+ return T(0);
+ case ONE:
+ return T(1);
+ case TWO:
+ return T(2);
+ case MIN:
+ return T::min();
+ case MAX:
+ return T::max();
+ }
+}
+
+using Types = testing::TypeList< //
+#ifdef LIBC_TYPES_HAS_INT64
+ BigInt<64, false, uint64_t>, // 64-bits unsigned (1 x uint64_t)
+ BigInt<64, true, uint64_t>, // 64-bits signed (1 x uint64_t)
+#endif
+#ifdef LIBC_TYPES_HAS_INT128
+ BigInt<128, false, __uint128_t>, // 128-bits unsigned (1 x __uint128_t)
+ BigInt<128, true, __uint128_t>, // 128-bits signed (1 x __uint128_t)
+#endif
+ BigInt<16, false, uint16_t>, // 16-bits unsigned (1 x uint16_t)
+ BigInt<16, true, uint16_t>, // 16-bits signed (1 x uint16_t)
+ BigInt<64, false, uint16_t>, // 64-bits unsigned (4 x uint16_t)
+ BigInt<64, true, uint16_t> // 64-bits signed (4 x uint16_t)
+ >;
+
+#define ASSERT_SAME(A, B) ASSERT_TRUE((A) == (B))
+
+TYPED_TEST(LlvmLibcUIntClassTest, Additions, Types) {
+ ASSERT_SAME(create<T>(ZERO) + create<T>(ZERO), create<T>(ZERO));
+ ASSERT_SAME(create<T>(ONE) + create<T>(ZERO), create<T>(ONE));
+ ASSERT_SAME(create<T>(ZERO) + create<T>(ONE), create<T>(ONE));
+ ASSERT_SAME(create<T>(ONE) + create<T>(ONE), create<T>(TWO));
+ // 2's complement addition works for signed and unsigned types.
+ // - unsigned : 0xff + 0x01 = 0x00 (255 + 1 = 0)
+ // - signed : 0xef + 0x01 = 0xf0 (127 + 1 = -128)
+ ASSERT_SAME(create<T>(MAX) + create<T>(ONE), create<T>(MIN));
+}
+
+TYPED_TEST(LlvmLibcUIntClassTest, Subtraction, Types) {
+ ASSERT_SAME(create<T>(ZERO) - create<T>(ZERO), create<T>(ZERO));
+ ASSERT_SAME(create<T>(ONE) - create<T>(ONE), create<T>(ZERO));
+ ASSERT_SAME(create<T>(ONE) - create<T>(ZERO), create<T>(ONE));
+ // 2's complement subtraction works for signed and unsigned types.
+ // - unsigned : 0x00 - 0x01 = 0xff ( 0 - 1 = 255)
+ // - signed : 0xf0 - 0x01 = 0xef (-128 - 1 = 127)
+ ASSERT_SAME(create<T>(MIN) - create<T>(ONE), create<T>(MAX));
+}
+
+TYPED_TEST(LlvmLibcUIntClassTest, Multiplication, Types) {
+ ASSERT_SAME(create<T>(ZERO) * create<T>(ZERO), create<T>(ZERO));
+ ASSERT_SAME(create<T>(ZERO) * create<T>(ONE), create<T>(ZERO));
+ ASSERT_SAME(create<T>(ONE) * create<T>(ZERO), create<T>(ZERO));
+ ASSERT_SAME(create<T>(ONE) * create<T>(ONE), create<T>(ONE));
+ ASSERT_SAME(create<T>(ONE) * create<T>(TWO), create<T>(TWO));
+ ASSERT_SAME(create<T>(TWO) * create<T>(ONE), create<T>(TWO));
+ // - unsigned : 0xff x 0xff = 0x01 (mod 0xff)
+ // - signed : 0xef x 0xef = 0x01 (mod 0xff)
+ ASSERT_SAME(create<T>(MAX) * create<T>(MAX), create<T>(ONE));
+}
+
+template <typename T> void print(const char *msg, T value) {
+ testing::tlog << msg;
+ IntegerToString<T, radix::Hex> buffer(value);
+ testing::tlog << buffer.view() << "\n";
+}
+
+TEST(LlvmLibcUIntClassTest, SignedAddSub) {
+ // Computations performed by https://www.wolframalpha.com/
+ using T = BigInt<128, true, uint32_t>;
+ const T a = parse_bigint<T>("1927508279017230597");
+ const T b = parse_bigint<T>("278789278723478925");
+ const T s = parse_bigint<T>("2206297557740709522");
+ // Addition
+ ASSERT_SAME(a + b, s);
+ ASSERT_SAME(b + a, s); // commutative
+ // Subtraction
+ ASSERT_SAME(a - s, -b);
+ ASSERT_SAME(s - a, b);
+}
+
+TEST(LlvmLibcUIntClassTest, SignedMulDiv) {
+ // Computations performed by https://www.wolframalpha.com/
+ using T = BigInt<128, true, uint16_t>;
+ struct {
+ const char *a;
+ const char *b;
+ const char *mul;
+ } const test_cases[] = {{"-4", "3", "-12"},
+ {"-3", "-3", "9"},
+ {"1927508279017230597", "278789278723478925",
+ "537368642840747885329125014794668225"}};
+ for (auto tc : test_cases) {
+ const T a = parse_bigint<T>(tc.a);
+ const T b = parse_bigint<T>(tc.b);
+ const T mul = parse_bigint<T>(tc.mul);
+ // Multiplication
+ ASSERT_SAME(a * b, mul);
+ ASSERT_SAME(b * a, mul); // commutative
+ ASSERT_SAME(a * -b, -mul); // sign
+ ASSERT_SAME(-a * b, -mul); // sign
+ ASSERT_SAME(-a * -b, mul); // sign
+ // Division
+ ASSERT_SAME(mul / a, b);
+ ASSERT_SAME(mul / b, a);
+ ASSERT_SAME(-mul / a, -b); // sign
+ ASSERT_SAME(mul / -a, -b); // sign
+ ASSERT_SAME(-mul / -a, b); // sign
+ }
+}
+
+TYPED_TEST(LlvmLibcUIntClassTest, Division, Types) {
+ ASSERT_SAME(create<T>(ZERO) / create<T>(ONE), create<T>(ZERO));
+ ASSERT_SAME(create<T>(MAX) / create<T>(ONE), create<T>(MAX));
+ ASSERT_SAME(create<T>(MAX) / create<T>(MAX), create<T>(ONE));
+ ASSERT_SAME(create<T>(ONE) / create<T>(ONE), create<T>(ONE));
+ if constexpr (T::SIGNED) {
+ // Special case found by fuzzing.
+ ASSERT_SAME(create<T>(MIN) / create<T>(MIN), create<T>(ONE));
+ }
+ // - unsigned : 0xff / 0x02 = 0x7f
+ // - signed : 0xef / 0x02 = 0x77
+ ASSERT_SAME(create<T>(MAX) / create<T>(TWO), (create<T>(MAX) >> 1));
+
+ using word_type = typename T::word_type;
+ const T zero_one_repeated = T::all_ones() / T(0xff);
+ const word_type pattern = word_type(~0) / word_type(0xff);
+ for (const word_type part : zero_one_repeated.val) {
+ if constexpr (T::SIGNED == false) {
+ EXPECT_EQ(part, pattern);
+ }
+ }
+}
+
+TYPED_TEST(LlvmLibcUIntClassTest, is_neg, Types) {
+ EXPECT_FALSE(create<T>(ZERO).is_neg());
+ EXPECT_FALSE(create<T>(ONE).is_neg());
+ EXPECT_FALSE(create<T>(TWO).is_neg());
+ EXPECT_EQ(create<T>(MIN).is_neg(), T::SIGNED);
+ EXPECT_FALSE(create<T>(MAX).is_neg());
+}
+
+TYPED_TEST(LlvmLibcUIntClassTest, Masks, Types) {
+ if constexpr (!T::SIGNED) {
+ constexpr size_t BITS = T::BITS;
+ // mask_trailing_ones
+ ASSERT_SAME((mask_trailing_ones<T, 0>()), T::zero());
+ ASSERT_SAME((mask_trailing_ones<T, 1>()), T::one());
+ ASSERT_SAME((mask_trailing_ones<T, BITS - 1>()), T::all_ones() >> 1);
+ ASSERT_SAME((mask_trailing_ones<T, BITS>()), T::all_ones());
+ // mask_leading_ones
+ ASSERT_SAME((mask_leading_ones<T, 0>()), T::zero());
+ ASSERT_SAME((mask_leading_ones<T, 1>()), T::one() << (BITS - 1));
+ ASSERT_SAME((mask_leading_ones<T, BITS - 1>()), T::all_ones() - T::one());
+ ASSERT_SAME((mask_leading_ones<T, BITS>()), T::all_ones());
+ // mask_trailing_zeros
+ ASSERT_SAME((mask_trailing_zeros<T, 0>()), T::all_ones());
+ ASSERT_SAME((mask_trailing_zeros<T, 1>()), T::all_ones() - T::one());
+ ASSERT_SAME((mask_trailing_zeros<T, BITS - 1>()), T::one() << (BITS - 1));
+ ASSERT_SAME((mask_trailing_zeros<T, BITS>()), T::zero());
+ // mask_trailing_zeros
+ ASSERT_SAME((mask_leading_zeros<T, 0>()), T::all_ones());
+ ASSERT_SAME((mask_leading_zeros<T, 1>()), T::all_ones() >> 1);
+ ASSERT_SAME((mask_leading_zeros<T, BITS - 1>()), T::one());
+ ASSERT_SAME((mask_leading_zeros<T, BITS>()), T::zero());
+ }
+}
+
+TYPED_TEST(LlvmLibcUIntClassTest, CountBits, Types) {
+ if constexpr (!T::SIGNED) {
+ for (size_t i = 0; i <= T::BITS; ++i) {
+ const auto l_one = T::all_ones() << i; // 0b111...000
+ const auto r_one = T::all_ones() >> i; // 0b000...111
+ const int zeros = i;
+ const int ones = T::BITS - zeros;
+ ASSERT_EQ(cpp::countr_one(r_one), ones);
+ ASSERT_EQ(cpp::countl_one(l_one), ones);
+ ASSERT_EQ(cpp::countr_zero(l_one), zeros);
+ ASSERT_EQ(cpp::countl_zero(r_one), zeros);
+ }
+ }
+}
+
using LL_UInt64 = UInt<64>;
// We want to test UInt<128> explicitly. So, for
// convenience, we use a sugar which does not conflict with the UInt128 type
@@ -561,7 +751,7 @@ TEST(LlvmLibcUIntClassTest, FullMulTests) {
LL_UInt##Bits a = ~LL_UInt##Bits(0); \
LL_UInt##Bits hi = a.quick_mul_hi(a); \
LL_UInt##Bits trunc = static_cast<LL_UInt##Bits>(a.ful_mul(a) >> Bits); \
- uint64_t overflow = trunc.sub(hi); \
+ uint64_t overflow = trunc.sub_overflow(hi); \
EXPECT_EQ(overflow, uint64_t(0)); \
EXPECT_LE(uint64_t(trunc), uint64_t(Error)); \
} while (0)
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index f8f0f8b..bbf8f07 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -638,6 +638,21 @@ add_fp_unittest(
)
add_fp_unittest(
+ exp2m1f_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ exp2m1f_test.cpp
+ DEPENDS
+ libc.include.llvm-libc-macros.math_macros
+ libc.src.errno.errno
+ libc.src.math.exp2m1f
+ libc.src.__support.CPP.array
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
exp10f_test
NEED_MPFR
SUITE
diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index df32dd4..6b2f3dd 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -143,6 +143,21 @@ add_fp_unittest(
)
add_fp_unittest(
+ exp2m1f_test
+ NO_RUN_POSTBUILD
+ NEED_MPFR
+ SUITE
+ libc_math_exhaustive_tests
+ SRCS
+ exp2m1f_test.cpp
+ DEPENDS
+ .exhaustive_test
+ libc.src.math.exp2m1f
+ LINK_LIBRARIES
+ -lpthread
+)
+
+add_fp_unittest(
exp10f_test
NO_RUN_POSTBUILD
NEED_MPFR
diff --git a/libc/test/src/math/exhaustive/exp2m1f_test.cpp b/libc/test/src/math/exhaustive/exp2m1f_test.cpp
new file mode 100644
index 0000000..2111024
--- /dev/null
+++ b/libc/test/src/math/exhaustive/exp2m1f_test.cpp
@@ -0,0 +1,33 @@
+//===-- Exhaustive test for exp2m1f ---------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "exhaustive_test.h"
+#include "src/math/exp2m1f.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+using LlvmLibcExp2m1fExhaustiveTest =
+ LlvmLibcUnaryOpExhaustiveMathTest<float, mpfr::Operation::Exp2m1,
+ LIBC_NAMESPACE::exp2m1f>;
+
+// Range: [0, Inf];
+static constexpr uint32_t POS_START = 0x0000'0000U;
+static constexpr uint32_t POS_STOP = 0x7f80'0000U;
+
+TEST_F(LlvmLibcExp2m1fExhaustiveTest, PostiveRange) {
+ test_full_range_all_roundings(POS_START, POS_STOP);
+}
+
+// Range: [-Inf, 0];
+static constexpr uint32_t NEG_START = 0x8000'0000U;
+static constexpr uint32_t NEG_STOP = 0xff80'0000U;
+
+TEST_F(LlvmLibcExp2m1fExhaustiveTest, NegativeRange) {
+ test_full_range_all_roundings(NEG_START, NEG_STOP);
+}
diff --git a/libc/test/src/math/exp2m1f_test.cpp b/libc/test/src/math/exp2m1f_test.cpp
new file mode 100644
index 0000000..a0f0da8
--- /dev/null
+++ b/libc/test/src/math/exp2m1f_test.cpp
@@ -0,0 +1,66 @@
+//===-- Unittests for exp2m1f ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "include/llvm-libc-macros/math-macros.h"
+#include "src/__support/CPP/array.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/errno/libc_errno.h"
+#include "src/math/exp2m1f.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+#include <stdint.h>
+
+using LlvmLibcExp2m1fTest = LIBC_NAMESPACE::testing::FPTest<float>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+TEST_F(LlvmLibcExp2m1fTest, TrickyInputs) {
+ constexpr LIBC_NAMESPACE::cpp::array<float, 10> INPUTS = {
+ // EXP2M1F_EXCEPTS_LO
+ 0x1.36dc8ep-36,
+ 0x1.224936p-19,
+ 0x1.d16d2p-20,
+ 0x1.17949ep-14,
+ -0x1.9c3e1ep-38,
+ -0x1.4d89b4p-32,
+ -0x1.a6eac4p-10,
+ -0x1.e7526ep-6,
+ // EXP2M1F_EXCEPTS_HI
+ 0x1.16a972p-1,
+ -0x1.9f12acp-5,
+ };
+
+ for (float x : INPUTS) {
+ LIBC_NAMESPACE::libc_errno = 0;
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2m1, x,
+ LIBC_NAMESPACE::exp2m1f(x), 0.5);
+ }
+}
+
+TEST_F(LlvmLibcExp2m1fTest, InFloatRange) {
+ constexpr uint32_t COUNT = 100'000;
+ constexpr uint32_t STEP = UINT32_MAX / COUNT;
+ for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
+ float x = FPBits(v).get_val();
+ if (isnan(x) || isinf(x))
+ continue;
+ LIBC_NAMESPACE::libc_errno = 0;
+ float result = LIBC_NAMESPACE::exp2m1f(x);
+
+ // If the computation resulted in an error or did not produce valid result
+ // in the single-precision floating point range, then ignore comparing with
+ // MPFR result as MPFR can still produce valid results because of its
+ // wider precision.
+ if (isnan(result) || isinf(result) || LIBC_NAMESPACE::libc_errno != 0)
+ continue;
+ ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2m1, x,
+ LIBC_NAMESPACE::exp2m1f(x), 0.5);
+ }
+}
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 5d269dd..4ac1842 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -774,6 +774,17 @@ add_fp_unittest(
)
add_fp_unittest(
+ exp2m1f_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ exp2m1f_test.cpp
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.exp2m1f
+)
+
+add_fp_unittest(
exp10f_test
SUITE
libc-math-smoke-tests
diff --git a/libc/test/src/math/smoke/exp2m1f_test.cpp b/libc/test/src/math/smoke/exp2m1f_test.cpp
new file mode 100644
index 0000000..2df4353
--- /dev/null
+++ b/libc/test/src/math/smoke/exp2m1f_test.cpp
@@ -0,0 +1,63 @@
+//===-- Unittests for exp2m1f ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/errno/libc_errno.h"
+#include "src/math/exp2m1f.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using LlvmLibcExp2m1fTest = LIBC_NAMESPACE::testing::FPTest<float>;
+using LIBC_NAMESPACE::fputil::testing::ForceRoundingMode;
+using LIBC_NAMESPACE::fputil::testing::RoundingMode;
+
+TEST_F(LlvmLibcExp2m1fTest, SpecialNumbers) {
+ LIBC_NAMESPACE::libc_errno = 0;
+
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::exp2m1f(aNaN));
+ EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::exp2m1f(inf));
+ EXPECT_FP_EQ_ALL_ROUNDING(-1.0f, LIBC_NAMESPACE::exp2m1f(neg_inf));
+ EXPECT_FP_EQ_ALL_ROUNDING(0.0f, LIBC_NAMESPACE::exp2m1f(0.0f));
+ EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, LIBC_NAMESPACE::exp2m1f(-0.0f));
+
+ EXPECT_FP_EQ_ALL_ROUNDING(1.0f, LIBC_NAMESPACE::exp2m1f(1.0f));
+ EXPECT_FP_EQ_ALL_ROUNDING(-0.5f, LIBC_NAMESPACE::exp2m1f(-1.0f));
+ EXPECT_FP_EQ_ALL_ROUNDING(3.0f, LIBC_NAMESPACE::exp2m1f(2.0f));
+ EXPECT_FP_EQ_ALL_ROUNDING(-0.75f, LIBC_NAMESPACE::exp2m1f(-2.0f));
+}
+
+TEST_F(LlvmLibcExp2m1fTest, Overflow) {
+ LIBC_NAMESPACE::libc_errno = 0;
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::exp2m1f(0x1.fffffep+127),
+ FE_OVERFLOW);
+ EXPECT_MATH_ERRNO(ERANGE);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::exp2m1f(128.0f),
+ FE_OVERFLOW);
+ EXPECT_MATH_ERRNO(ERANGE);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::exp2m1f(0x1.000002p+7),
+ FE_OVERFLOW);
+ EXPECT_MATH_ERRNO(ERANGE);
+}
+
+TEST_F(LlvmLibcExp2m1fTest, Underflow) {
+ LIBC_NAMESPACE::libc_errno = 0;
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(-1.0f, LIBC_NAMESPACE::exp2m1f(-0x1.fffffep+127),
+ FE_UNDERFLOW);
+ EXPECT_MATH_ERRNO(ERANGE);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(-1.0f, LIBC_NAMESPACE::exp2m1f(-25.0f),
+ FE_UNDERFLOW);
+ EXPECT_MATH_ERRNO(ERANGE);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(-1.0f, LIBC_NAMESPACE::exp2m1f(-0x1.900002p4),
+ FE_UNDERFLOW);
+ EXPECT_MATH_ERRNO(ERANGE);
+}