llvm.org GIT mirror llvm / bfaa9ed
Fix APFloat mod sign fmod specification requires the sign of the remainder is the same as numerator in case remainder is zero. Reviewers: gottesmm, scanon, arsenm, davide, craig.topper Reviewed By: scanon Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D39225 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317081 91177308-0d34-0410-b5e6-96231b3b80d8 Serguei Katkov 1 year, 9 months ago
2 changed file(s) with 17 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
17421742 IEEEFloat::opStatus IEEEFloat::mod(const IEEEFloat &rhs) {
17431743 opStatus fs;
17441744 fs = modSpecials(rhs);
1745 unsigned int origSign = sign;
17451746
17461747 while (isFiniteNonZero() && rhs.isFiniteNonZero() &&
17471748 compareAbsoluteValue(rhs) != cmpLessThan) {
17531754 fs = subtract(V, rmNearestTiesToEven);
17541755 assert(fs==opOK);
17551756 }
1757 if (isZero())
1758 sign = origSign; // fmod requires this
17561759 return fs;
17571760 }
17581761
32873287 APFloat f2(APFloat::IEEEdouble(), "1.0");
32883288 EXPECT_EQ(f1.mod(f2), APFloat::opInvalidOp);
32893289 EXPECT_TRUE(f1.isNaN());
3290 }
3291 {
3292 APFloat f1(APFloat::IEEEdouble(), "-4.0");
3293 APFloat f2(APFloat::IEEEdouble(), "-2.0");
3294 APFloat expected(APFloat::IEEEdouble(), "-0.0");
3295 EXPECT_EQ(f1.mod(f2), APFloat::opOK);
3296 EXPECT_TRUE(f1.bitwiseIsEqual(expected));
3297 }
3298 {
3299 APFloat f1(APFloat::IEEEdouble(), "-4.0");
3300 APFloat f2(APFloat::IEEEdouble(), "2.0");
3301 APFloat expected(APFloat::IEEEdouble(), "-0.0");
3302 EXPECT_EQ(f1.mod(f2), APFloat::opOK);
3303 EXPECT_TRUE(f1.bitwiseIsEqual(expected));
32903304 }
32913305 }
32923306