[PATCH] D111917: Print the sign of negative infinity

Logan Chien via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 13 23:02:43 PST 2021


Hi,

May someone please take a look at this 3-line patch (
https://reviews.llvm.org/D111917)?

With this patch, we can correctly print negative infinity as "-INF".

Before this patch, both positive infinity and negative infinity were
printed as "INF", which was incorrect in my opinion.

Thank you for your time.

Regards,
Logan

On Sun, Oct 24, 2021 at 9:57 AM Logan Chien <tzuhsiang.chien at gmail.com>
wrote:

> Hi,
>
> May someone please take a look?
>
> This patch fixes a case where -inf is printed as "INF".
>
> Thank you.
>
> Regards,
> Logan
>
> On Fri, Oct 15, 2021 at 5:51 PM Logan Chien via Phabricator <
> reviews at reviews.llvm.org> wrote:
>
>> logan created this revision.
>> Herald added subscribers: dexonsmith, hiraditya.
>> logan requested review of this revision.
>> Herald added a project: LLVM.
>> Herald added a subscriber: llvm-commits.
>>
>> This commit makes `llvm::write_double` print `-inf` as `"-INF"` instead
>> of `"INF"`.
>>
>>
>> https://reviews.llvm.org/D111917
>>
>> Files:
>>   llvm/lib/Support/NativeFormatting.cpp
>>   llvm/unittests/Support/NativeFormatTests.cpp
>>
>>
>> Index: llvm/unittests/Support/NativeFormatTests.cpp
>> ===================================================================
>> --- llvm/unittests/Support/NativeFormatTests.cpp
>> +++ llvm/unittests/Support/NativeFormatTests.cpp
>> @@ -125,6 +125,8 @@
>>                                   FloatStyle::Fixed));
>>    EXPECT_EQ("INF", format_number(std::numeric_limits<double>::infinity(),
>>                                   FloatStyle::Fixed));
>> +  EXPECT_EQ("-INF",
>> format_number(-std::numeric_limits<double>::infinity(),
>> +                                  FloatStyle::Fixed));
>>  }
>>
>>  TEST(NativeFormatTest, HexTests) {
>> Index: llvm/lib/Support/NativeFormatting.cpp
>> ===================================================================
>> --- llvm/lib/Support/NativeFormatting.cpp
>> +++ llvm/lib/Support/NativeFormatting.cpp
>> @@ -168,7 +168,7 @@
>>      S << "nan";
>>      return;
>>    } else if (std::isinf(N)) {
>> -    S << "INF";
>> +    S << (std::signbit(N) ? "-INF" : "INF");
>>      return;
>>    }
>>
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211213/1a31a745/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111917.diff
Type: text/x-patch
Size: 958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211213/1a31a745/attachment.bin>


More information about the llvm-commits mailing list