class ScaledNumberBase {
public:
- static const int32_t MaxScale = 16383;
- static const int32_t MinScale = -16382;
static const int DefaultPrecision = 10;
static void dump(uint64_t D, int16_t E, int Width);
static ScaledNumber getZero() { return ScaledNumber(0, 0); }
static ScaledNumber getOne() { return ScaledNumber(1, 0); }
static ScaledNumber getLargest() {
- return ScaledNumber(DigitsLimits::max(), MaxScale);
+ return ScaledNumber(DigitsLimits::max(), ScaledNumbers::MaxScale);
}
static ScaledNumber getFloat(uint64_t N) { return adjustToWidth(N, 0); }
static ScaledNumber getInverseFloat(uint64_t N) {
std::tie(Digits, Scale) =
ScaledNumbers::getSum(Digits, Scale, X.Digits, X.Scale);
// Check for exponent past MaxScale.
- if (Scale > MaxScale)
+ if (Scale > ScaledNumbers::MaxScale)
*this = getLargest();
return *this;
}
///
/// \pre Shift >= MinScale && Shift + 64 <= MaxScale.
static ScaledNumber adjustToWidth(uint64_t N, int32_t Shift) {
- assert(Shift >= MinScale && "Shift should be close to 0");
- assert(Shift <= MaxScale - 64 && "Shift should be close to 0");
+ assert(Shift >= ScaledNumbers::MinScale && "Shift should be close to 0");
+ assert(Shift <= ScaledNumbers::MaxScale - 64 &&
+ "Shift should be close to 0");
auto Adjusted = ScaledNumbers::getAdjusted<DigitsT>(N, Shift);
return Adjusted;
}
}
// Shift as much as we can in the exponent.
- int32_t ScaleShift = std::min(Shift, MaxScale - Scale);
+ int32_t ScaleShift = std::min(Shift, ScaledNumbers::MaxScale - Scale);
Scale += ScaleShift;
if (ScaleShift == Shift)
return;
}
// Shift as much as we can in the exponent.
- int32_t ScaleShift = std::min(Shift, Scale - MinScale);
+ int32_t ScaleShift = std::min(Shift, Scale - ScaledNumbers::MinScale);
Scale -= ScaleShift;
if (ScaleShift == Shift)
return;
namespace llvm {
namespace ScaledNumbers {
+/// \brief Maximum scale; same as APFloat for easy debug printing.
+const int32_t MaxScale = 16383;
+
+/// \brief Maximum scale; same as APFloat for easy debug printing.
+const int32_t MinScale = -16382;
+
/// \brief Get the width of a number.
template <class DigitsT> inline int getWidth() { return sizeof(DigitsT) * 8; }
// ScaledNumber implementation.
//
//===----------------------------------------------------------------------===//
-#ifndef _MSC_VER
-const int32_t ScaledNumberBase::MaxScale;
-const int32_t ScaledNumberBase::MinScale;
-#endif
-
static void appendDigit(std::string &Str, unsigned D) {
assert(D < 10);
Str += '0' + D % 10;
}
static std::string toStringAPFloat(uint64_t D, int E, unsigned Precision) {
- assert(E >= ScaledNumberBase::MinScale);
- assert(E <= ScaledNumberBase::MaxScale);
+ assert(E >= ScaledNumbers::MinScale);
+ assert(E <= ScaledNumbers::MaxScale);
// Find a new E, but don't let it increase past MaxScale.
int LeadingZeros = ScaledNumberBase::countLeadingZeros64(D);
- int NewE = std::min(ScaledNumberBase::MaxScale, E + 63 - LeadingZeros);
+ int NewE = std::min(ScaledNumbers::MaxScale, E + 63 - LeadingZeros);
int Shift = 63 - (NewE - E);
assert(Shift <= LeadingZeros);
- assert(Shift == LeadingZeros || NewE == ScaledNumberBase::MaxScale);
+ assert(Shift == LeadingZeros || NewE == ScaledNumbers::MaxScale);
D <<= Shift;
E = NewE;
// Check for a denormal.
unsigned AdjustedE = E + 16383;
if (!(D >> 63)) {
- assert(E == ScaledNumberBase::MaxScale);
+ assert(E == ScaledNumbers::MaxScale);
AdjustedE = 0;
}