Attempt #3 for getting a portable INFINITY value.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34454
91177308-0d34-0410-b5e6-
96231b3b80d8
#include "llvm/Support/MathExtras.h"
#include <cstring>
#include <cstdlib>
#include "llvm/Support/MathExtras.h"
#include <cstring>
#include <cstdlib>
using namespace llvm;
// A utility function for allocating memory, checking for allocation failures,
using namespace llvm;
// A utility function for allocating memory, checking for allocation failures,
/// given APInt& RHS and assigns the result to this APInt.
APInt& APInt::operator*=(const APInt& RHS) {
assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
/// given APInt& RHS and assigns the result to this APInt.
APInt& APInt::operator*=(const APInt& RHS) {
assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
- if (isSingleWord()) VAL *= RHS.isSingleWord() ? RHS.VAL : RHS.pVal[0];
+ if (isSingleWord())
+ VAL *= RHS.VAL;
else {
// one-based first non-zero bit position.
uint32_t first = getActiveBits();
else {
// one-based first non-zero bit position.
uint32_t first = getActiveBits();
/// RHS.
APInt APInt::operator*(const APInt& RHS) const {
assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
/// RHS.
APInt APInt::operator*(const APInt& RHS) const {
assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
- APInt API(RHS);
- API *= *this;
- API.clearUnusedBits();
- return API;
+ APInt Result(*this);
+ Result *= RHS;
+ Result.clearUnusedBits();
+ return Result;
}
/// @brief Addition operator. Adds this APInt by the given APInt& RHS.
}
/// @brief Addition operator. Adds this APInt by the given APInt& RHS.
// Return infinity for exponent overflow
if (exp > 1023) {
if (!isSigned || !isNeg)
// Return infinity for exponent overflow
if (exp > 1023) {
if (!isSigned || !isNeg)
- return double(INFINITY); // positive infinity
+ return double(1.0E300 * 1.0E300); // positive infinity
- return double(-INFINITY); // negative infinity
+ return double(-1.0E300 * 1.0E300); // negative infinity
}
exp += 1023; // Increment for 1023 bias
}
exp += 1023; // Increment for 1023 bias