diff options
| author | Dale Johannesen <dalej@apple.com> | 2009-01-20 18:35:05 +0000 | 
|---|---|---|
| committer | Dale Johannesen <dalej@apple.com> | 2009-01-20 18:35:05 +0000 | 
| commit | fe750179fff2bf9a11b331c95ca8315522694946 (patch) | |
| tree | 4c1ccb52b4316895acbdd79b518a7e38a81ca5ee /llvm/lib | |
| parent | 17844c7a880c70a6a6a8b8506a423ad125448153 (diff) | |
| download | bcm5719-llvm-fe750179fff2bf9a11b331c95ca8315522694946.tar.gz bcm5719-llvm-fe750179fff2bf9a11b331c95ca8315522694946.zip | |
Add an IEEE remainder function, which is not
fully implemented yet and not used.  This is
mainly to clarify that APFloat::mod implements
C fmod, not remainder.
llvm-svn: 62593
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Support/APFloat.cpp | 40 | 
1 files changed, 39 insertions, 1 deletions
| diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index fde157d60fc..151f9d5b392 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -1514,7 +1514,45 @@ APFloat::divide(const APFloat &rhs, roundingMode rounding_mode)    return fs;  } -/* Normalized remainder.  This is not currently doing TRT.  */ +/* Normalized remainder.  This is not currently correct in all cases.  */ +APFloat::opStatus +APFloat::remainder(const APFloat &rhs) +{ +  opStatus fs; +  APFloat V = *this; +  unsigned int origSign = sign; + +  assertArithmeticOK(*semantics); +  fs = V.divide(rhs, rmNearestTiesToEven); +  if (fs == opDivByZero) +    return fs; + +  int parts = partCount(); +  integerPart *x = new integerPart[parts]; +  bool ignored; +  fs = V.convertToInteger(x, parts * integerPartWidth, true, +                          rmNearestTiesToEven, &ignored); +  if (fs==opInvalidOp) +    return fs; + +  fs = V.convertFromZeroExtendedInteger(x, parts * integerPartWidth, true, +                                        rmNearestTiesToEven); +  assert(fs==opOK);   // should always work + +  fs = V.multiply(rhs, rmNearestTiesToEven); +  assert(fs==opOK || fs==opInexact);   // should not overflow or underflow + +  fs = subtract(V, rmNearestTiesToEven); +  assert(fs==opOK || fs==opInexact);   // likewise + +  if (isZero()) +    sign = origSign;    // IEEE754 requires this +  delete[] x; +  return fs; +} + +/* Normalized llvm frem (C fmod).   +   This is not currently correct in all cases.  */  APFloat::opStatus  APFloat::mod(const APFloat &rhs, roundingMode rounding_mode)  { | 

