[flang] start negative number tests

Original-commit: flang-compiler/f18@1b52ec8d3b
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2018-06-06 11:48:00 -07:00
parent 99c23c1a92
commit 518b2094b2
2 changed files with 30 additions and 6 deletions

View File

@ -39,8 +39,8 @@ public:
constexpr Real() {} // +0.0
constexpr Real(const Real &) = default;
constexpr Real &operator=(const Real &) = default;
constexpr Real(const Word &bits) : word_{bits} {}
constexpr Real &operator=(const Real &) = default;
template<typename INT>
static constexpr ValueWithRealFlags<Real> ConvertSigned(
@ -76,9 +76,7 @@ public:
// HUGE, INT/NINT, MAXEXPONENT, MINEXPONENT, NEAREST, OUT_OF_RANGE,
// PRECISION, HUGE, TINY, RRSPACING/SPACING, SCALE, SET_EXPONENT, SIGN
constexpr Word RawBits() const {
return word_;
}
constexpr Word RawBits() const { return word_; }
constexpr std::uint64_t Exponent() const {
return word_.IBITS(significandBits, exponentBits).ToUInt64();
}
@ -131,7 +129,7 @@ public:
result.flags.set(RealFlag::InvalidArgument);
result.value = result.value.HUGE();
} else if (exponent >= maxExponent || // +/-Inf
exponent >= exponentBias + result.value.bits) { // too big
exponent >= exponentBias + result.value.bits) { // too big
if (isNegative) {
result.value = result.value.MASKL(1);
} else {
@ -381,7 +379,8 @@ private:
}
template<typename INT>
static constexpr RoundingBits GetRoundingBits(const INT &fraction, int rshift) {
static constexpr RoundingBits GetRoundingBits(
const INT &fraction, int rshift) {
RoundingBits roundingBits;
if (rshift > fraction.bits) {
roundingBits.guard = !fraction.IsZero();

View File

@ -92,6 +92,7 @@ template<typename R> void tests() {
std::uint64_t x{1};
x <<= j;
Integer<64> ix{x};
TEST(!ix.IsNegative())("%s,%d,0x%llx",desc,j,x);
MATCH(x, ix.ToUInt64())("%s,%d,0x%llx",desc,j,x);
vr = R::ConvertSigned(ix);
TEST(!vr.value.IsNegative())("%s,%d,0x%llx",desc,j,x);
@ -110,6 +111,30 @@ template<typename R> void tests() {
MATCH(x, ivf.value.ToUInt64())("%s,%d,0x%llx",desc,j,x);
}
}
for (std::uint64_t j{0}; j < 64; ++j) {
std::uint64_t x{1};
x <<= j;
x |= std::uint64_t{1} << 63;
Integer<64> ix{x};
TEST(ix.IsNegative())("%s,%d,0x%llx",desc,j,x);
MATCH(x, ix.ToUInt64())("%s,%d,0x%llx",desc,j,x);
vr = R::ConvertSigned(ix, Rounding::ToZero);
TEST(vr.value.IsNegative())("%s,%d,0x%llx",desc,j,x);
TEST(!vr.value.IsNotANumber())("%s,%d,0x%llx",desc,j,x);
TEST(!vr.value.IsZero())("%s,%d,0x%llx",desc,j,x);
auto ivf = vr.value.template ToInteger<Integer<64>>();
if (j > (maxExponent / 2)) {
TEST(vr.flags.test(RealFlag::Overflow))(desc);
TEST(vr.value.IsInfinite())("%s,%d,0x%llx",desc,j,x);
TEST(ivf.flags.test(RealFlag::Overflow))("%s,%d,0x%llx",desc,j,x);
MATCH(0x8000000000000000, ivf.value.ToUInt64())("%s,%d,0x%llx",desc,j,x);
} else {
TEST(vr.flags.empty())(desc);
TEST(!vr.value.IsInfinite())("%s,%d,0x%llx",desc,j,x);
TEST(ivf.flags.empty())("%s,%d,0x%llx",desc,j,x);
MATCH(x, ivf.value.ToUInt64())("%s,%d,0x%llx",desc,j,x);
}
}
}
int main() {