[libc-commits] [libc] [libc][math][c23] Add hypotf16() function (PR #131991)
via libc-commits
libc-commits at lists.llvm.org
Tue Mar 25 07:31:43 PDT 2025
================
@@ -0,0 +1,58 @@
+//===-- Exhaustive test for hypotf16 --------------------------------------===//
+//
+// 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/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/Hypot.h"
+#include "src/math/hypotf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// Range of both inputs: [0, inf]
+static constexpr uint16_t START = 0x0000U;
+static constexpr uint16_t STOP = 0x7C00U;
+
+struct Hypotf16Checker : public virtual LIBC_NAMESPACE::testing::Test {
+ using FloatType = float16;
+ using FPBits = LIBC_NAMESPACE::fputil::FPBits<float16>;
+ using StorageType = typename FPBits::StorageType;
+
+ uint64_t check(uint16_t start, uint16_t stop, mpfr::RoundingMode rounding) {
+ mpfr::ForceRoundingMode r(rounding);
+ if (!r.success)
+ return true;
+ uint16_t xbits = start;
+ uint64_t failed = 0;
+ do {
+ float16 x = FPBits(xbits).get_val();
+ uint16_t ybits = xbits;
+ do {
+ float16 y = FPBits(ybits).get_val();
+ bool correct = TEST_FP_EQ(LIBC_NAMESPACE::fputil::hypot(x, y),
+ LIBC_NAMESPACE::hypotf16(x, y));
+ // Using MPFR will be much slower.
----------------
lntue wrote:
How long did it take for you to run the exhaustive tests? With and without mpfr?
https://github.com/llvm/llvm-project/pull/131991
More information about the libc-commits
mailing list