-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc][math] Fix signaling nan handling of hypot(f) and improve hypotf performance. #99432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,42 +9,29 @@ | |
#ifndef LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H | ||
#define LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H | ||
|
||
#include "src/__support/FPUtil/FPBits.h" | ||
#include "test/UnitTest/FEnvSafeTest.h" | ||
#include "test/UnitTest/FPMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
#include "hdr/math_macros.h" | ||
|
||
template <typename T> | ||
class HypotTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { | ||
class HypotTestTemplate : public LIBC_NAMESPACE::testing::Test { | ||
private: | ||
using Func = T (*)(T, T); | ||
using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>; | ||
using StorageType = typename FPBits::StorageType; | ||
|
||
const T nan = FPBits::quiet_nan().get_val(); | ||
const T inf = FPBits::inf(Sign::POS).get_val(); | ||
const T neg_inf = FPBits::inf(Sign::NEG).get_val(); | ||
const T zero = FPBits::zero(Sign::POS).get_val(); | ||
const T neg_zero = FPBits::zero(Sign::NEG).get_val(); | ||
|
||
const T max_normal = FPBits::max_normal().get_val(); | ||
const T min_normal = FPBits::min_normal().get_val(); | ||
const T max_subnormal = FPBits::max_subnormal().get_val(); | ||
const T min_subnormal = FPBits::min_subnormal().get_val(); | ||
DECLARE_SPECIAL_CONSTANTS(T) | ||
|
||
public: | ||
void test_special_numbers(Func func) { | ||
constexpr int N = 4; | ||
// Pythagorean triples. | ||
constexpr T PYT[N][3] = {{3, 4, 5}, {5, 12, 13}, {8, 15, 17}, {7, 24, 25}}; | ||
|
||
EXPECT_FP_EQ(func(inf, nan), inf); | ||
EXPECT_FP_EQ(func(nan, neg_inf), inf); | ||
EXPECT_FP_EQ(func(nan, nan), nan); | ||
EXPECT_FP_EQ(func(nan, zero), nan); | ||
EXPECT_FP_EQ(func(neg_zero, nan), nan); | ||
EXPECT_FP_EQ(func(inf, sNaN), aNaN); | ||
EXPECT_FP_EQ(func(sNaN, neg_inf), aNaN); | ||
EXPECT_FP_EQ(func(inf, aNaN), inf); | ||
EXPECT_FP_EQ(func(aNaN, neg_inf), inf); | ||
EXPECT_FP_EQ(func(aNaN, aNaN), aNaN); | ||
EXPECT_FP_EQ(func(aNaN, zero), aNaN); | ||
EXPECT_FP_EQ(func(neg_zero, aNaN), aNaN); | ||
Comment on lines
+28
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely, we should make a sweeping change for this at some point. |
||
|
||
for (int i = 0; i < N; ++i) { | ||
EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], PYT[i][1])); | ||
|
Uh oh!
There was an error while loading. Please reload this page.