File tree 2 files changed +11
-1
lines changed 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -1046,7 +1046,10 @@ class APFloat : public APFloatBase {
1046
1046
// /
1047
1047
// / \param Negative True iff the number should be negative.
1048
1048
static APFloat getOne (const fltSemantics &Sem, bool Negative = false ) {
1049
- return APFloat (Sem, Negative ? -1 : 1 );
1049
+ APFloat Val (Sem, 1U );
1050
+ if (Negative)
1051
+ Val.changeSign ();
1052
+ return Val;
1050
1053
}
1051
1054
1052
1055
// / Factory for Positive and Negative Infinity.
Original file line number Diff line number Diff line change @@ -892,6 +892,13 @@ TEST(APFloatTest, Zero) {
892
892
EXPECT_EQ(fcNegZero, APFloat(-0.0).classify());
893
893
}
894
894
895
+ TEST(APFloatTest, getOne) {
896
+ EXPECT_EQ(APFloat::getOne(APFloat::IEEEsingle(), false).convertToFloat(),
897
+ 1.0f);
898
+ EXPECT_EQ(APFloat::getOne(APFloat::IEEEsingle(), true).convertToFloat(),
899
+ -1.0f);
900
+ }
901
+
895
902
TEST(APFloatTest, DecimalStringsWithoutNullTerminators) {
896
903
// Make sure that we can parse strings without null terminators.
897
904
// rdar://14323230.
You can’t perform that action at this time.
0 commit comments