diff options
author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2024-10-15 13:35:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-15 13:35:50 +0800 |
commit | a54d88f97dfeb35e4f6c14e5563ec686e68fd244 (patch) | |
tree | 4e8f0c5f4cfc43e912630a930bfff32f8afc984a /llvm/unittests/ADT/APFloatTest.cpp | |
parent | b3a8400afa460a8372016e1abe5729cd4949b7d2 (diff) | |
download | llvm-a54d88f97dfeb35e4f6c14e5563ec686e68fd244.zip llvm-a54d88f97dfeb35e4f6c14e5563ec686e68fd244.tar.gz llvm-a54d88f97dfeb35e4f6c14e5563ec686e68fd244.tar.bz2 |
[APFloat] Fix `APFloat::getOne` (#112308)
`APFloat::APFloat(const fltSemantics &Semantics, integerPart I)`
interprets 'I' as a unsigned integer.
Fix the bug found in
https://github.com/llvm/llvm-project/pull/112113#discussion_r1799744541.
Diffstat (limited to 'llvm/unittests/ADT/APFloatTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/APFloatTest.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/APFloatTest.cpp b/llvm/unittests/ADT/APFloatTest.cpp index 6008f00..665cff9 100644 --- a/llvm/unittests/ADT/APFloatTest.cpp +++ b/llvm/unittests/ADT/APFloatTest.cpp @@ -892,6 +892,13 @@ TEST(APFloatTest, Zero) { EXPECT_EQ(fcNegZero, APFloat(-0.0).classify()); } +TEST(APFloatTest, getOne) { + EXPECT_EQ(APFloat::getOne(APFloat::IEEEsingle(), false).convertToFloat(), + 1.0f); + EXPECT_EQ(APFloat::getOne(APFloat::IEEEsingle(), true).convertToFloat(), + -1.0f); +} + TEST(APFloatTest, DecimalStringsWithoutNullTerminators) { // Make sure that we can parse strings without null terminators. // rdar://14323230. |