[libc-commits] [libc] [libc][math][c23] Add exp10m1f C23 math function (PR #87992)

via libc-commits libc-commits at lists.llvm.org
Tue Apr 9 16:24:44 PDT 2024


================
@@ -0,0 +1,59 @@
+//===-- Unittests for exp10m1f --------------------------------------------===//
+//
+// 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/exp10m1f.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using LlvmLibcExp10m1fTest = LIBC_NAMESPACE::testing::FPTest<float>;
+
+TEST_F(LlvmLibcExp10m1fTest, SpecialNumbers) {
+  LIBC_NAMESPACE::libc_errno = 0;
+
+  EXPECT_EQ(FPBits(aNaN).uintval(),
+            FPBits(LIBC_NAMESPACE::exp10m1f(aNaN)).uintval());
+  EXPECT_EQ(FPBits(neg_aNaN).uintval(),
+            FPBits(LIBC_NAMESPACE::exp10m1f(neg_aNaN)).uintval());
----------------
overmighty wrote:

On my x86-64 machine, this new `neg_aNaN` test was unluckily still succeeding when `exp10m1f` was not taking the `if (xbits.is_nan())` branch. The NaN `double` changes through the computations and the cast of the final result to `float` gives the same value as `neg_aNaN`.

I'm not sure when I should just use the unary `-` operator and when I should add new constants in FPMatcher.h. In this case, I didn't find a definition of the behavior of `-aNaN` and I'm not sure if it will work as expected on all architectures, so I added a new constant for `FPBits::quiet_nan(Sign::NEG)`. In the `Underflow` test below, I used `-max_normal` instead of defining `neg_max_normal` again like I did in `DECLARE_SPECIAL_CONSTANTS` when I implemented `fromfp`.

https://github.com/llvm/llvm-project/pull/87992


More information about the libc-commits mailing list