[libc-commits] [libc] [libc][math][c23] Fix X86_80 Special Case (PR #86924)
Shourya Goel via libc-commits
libc-commits at lists.llvm.org
Thu Mar 28 02:19:57 PDT 2024
https://github.com/Sh0g0-1758 created https://github.com/llvm/llvm-project/pull/86924
Updates the special case of pseudo infinty as pointed in #85940
>From 3ba418899bacffc8076befad68140f272a4ff5c4 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Thu, 28 Mar 2024 14:48:06 +0530
Subject: [PATCH] fix infinity
---
libc/src/__support/FPUtil/BasicOperations.h | 10 ++++++----
libc/test/src/math/smoke/CanonicalizeTest.h | 6 +++---
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index a47931bb33900a..bdb91a98a0d357 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -185,7 +185,7 @@ LIBC_INLINE int canonicalize(T &cx, const T &x) {
// More precisely :
// Exponent | Significand | Meaning
// | Bits 63-62 | Bits 61-0 |
- // All Ones | 00 | Zero | Pseudo Infinity, Value = Infinty
+ // All Ones | 00 | Zero | Pseudo Infinity, Value = SNaN
// All Ones | 00 | Non-Zero | Pseudo NaN, Value = SNaN
// All Ones | 01 | Anything | Pseudo NaN, Value = SNaN
// | Bit 63 | Bits 62-0 |
@@ -199,9 +199,11 @@ LIBC_INLINE int canonicalize(T &cx, const T &x) {
int exponent = sx.get_biased_exponent();
if (exponent == 0x7FFF) {
if (!bit63 && !bit62) {
- if (mantissa == 0)
- cx = FPBits<T>::inf(sx.sign()).get_val();
- else {
+ if (mantissa == 0) {
+ cx = FPBits<T>::quiet_nan(sx.sign(), mantissa).get_val();
+ raise_except_if_required(FE_INVALID);
+ return 1;
+ } else {
cx = FPBits<T>::quiet_nan(sx.sign(), mantissa).get_val();
raise_except_if_required(FE_INVALID);
return 1;
diff --git a/libc/test/src/math/smoke/CanonicalizeTest.h b/libc/test/src/math/smoke/CanonicalizeTest.h
index c8af83f1983881..1891d47922cf88 100644
--- a/libc/test/src/math/smoke/CanonicalizeTest.h
+++ b/libc/test/src/math/smoke/CanonicalizeTest.h
@@ -55,12 +55,12 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
T cx;
// Exponent | Significand | Meaning
// | Bits 63-62 | Bits 61-0 |
- // All Ones | 00 | Zero | Pseudo Infinity, Value = Infinty
+ // All Ones | 00 | Zero | Pseudo Infinity, Value = SNaN
FPBits test1((UInt128(0x7FFF) << 64) + UInt128(0x0000000000000000));
const T test1_val = test1.get_val();
- TEST_SPECIAL(cx, test1_val, 0, 0);
- EXPECT_FP_EQ(cx, inf);
+ TEST_SPECIAL(cx, test1_val, 1, FE_INVALID);
+ EXPECT_FP_EQ(cx, aNaN);
// Exponent | Significand | Meaning
// | Bits 63-62 | Bits 61-0 |
More information about the libc-commits
mailing list