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
This commit is contained in:
Serguei Katkov
2017-11-01 07:56:55 +00:00
parent 5d7d418e3b
commit bfaa9edde9
2 changed files with 17 additions and 0 deletions
+3
View File
@@ -1743,6 +1743,7 @@ IEEEFloat::opStatus IEEEFloat::remainder(const IEEEFloat &rhs) {
IEEEFloat::opStatus IEEEFloat::mod(const IEEEFloat &rhs) {
opStatus fs;
fs = modSpecials(rhs);
unsigned int origSign = sign;
while (isFiniteNonZero() && rhs.isFiniteNonZero() &&
compareAbsoluteValue(rhs) != cmpLessThan) {
@@ -1754,6 +1755,8 @@ IEEEFloat::opStatus IEEEFloat::mod(const IEEEFloat &rhs) {
fs = subtract(V, rmNearestTiesToEven);
assert(fs==opOK);
}
if (isZero())
sign = origSign; // fmod requires this
return fs;
}