File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 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 {
10461046 // /
10471047 // / \param Negative True iff the number should be negative.
10481048 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;
10501053 }
10511054
10521055 // / Factory for Positive and Negative Infinity.
Original file line number Diff line number Diff line change @@ -892,6 +892,13 @@ TEST(APFloatTest, Zero) {
892892 EXPECT_EQ (fcNegZero, APFloat (-0.0 ).classify ());
893893}
894894
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+
895902TEST (APFloatTest, DecimalStringsWithoutNullTerminators) {
896903 // Make sure that we can parse strings without null terminators.
897904 // rdar://14323230.
You can’t perform that action at this time.
0 commit comments