[flang] Get back to passing all tests.

Original-commit: flang-compiler/f18@d08dc86ede
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:26:00 -07:00
parent 3fb4757cc7
commit 99c23c1a92
2 changed files with 11 additions and 8 deletions

View File

@ -123,28 +123,31 @@ public:
}
template<typename INT> constexpr ValueWithRealFlags<INT> ToInteger() const {
ValueWithRealFlags<INT> result;
bool isNegative{IsNegative()};
std::uint64_t exponent{Exponent()};
Fraction fraction{GetFraction()};
ValueWithRealFlags<INT> result;
if (exponent == maxExponent && !fraction.IsZero()) { // NaN
result.flags.set(RealFlag::InvalidArgument);
result.value = result.value.HUGE();
} else if (exponent >= maxExponent || exponent >= exponentBias + result.value.bits) { // +/-Inf
} else if (exponent >= maxExponent || // +/-Inf
exponent >= exponentBias + result.value.bits) { // too big
if (isNegative) {
result.value = result.value.MASKL(1);
} else {
result.value = result.value.HUGE();
}
result.flags.set(RealFlag::Overflow);
} else if (exponent < exponentBias) { // |x| < 1.0
} else if (exponent < exponentBias) { // |x| < 1.0 -> 0
if (!fraction.IsZero()) {
result.flags.set(RealFlag::Underflow);
result.flags.set(RealFlag::Inexact);
}
} else {
if (exponent < exponentBias + significandBits) {
int rshift = exponentBias + significandBits - exponent;
// finite number |x| >= 1.0
constexpr std::uint64_t noShiftExponent{exponentBias + precision - 1};
if (exponent < noShiftExponent) {
int rshift = noShiftExponent - exponent;
if (!fraction.IBITS(0, rshift).IsZero()) {
result.flags.set(RealFlag::Inexact);
}
@ -155,7 +158,7 @@ public:
result.value = truncated.value;
}
} else {
int lshift = exponent - (exponentBias + significandBits);
int lshift = exponent - noShiftExponent;
if (lshift + precision >= result.value.bits) {
result.flags.set(RealFlag::Overflow);
} else {

View File

@ -43,7 +43,7 @@ FailureDetailPrinter Test(
return BitBucket;
} else {
++failures;
fprintf(stderr, "%s:%d: FAIL %s\n", file, line, predicate);
fprintf(stderr, "%s:%d: FAIL: %s\n", file, line, predicate);
return PrintFailureDetails;
}
}
@ -90,7 +90,7 @@ FailureDetailPrinter Compare(const char *file, int line, const char *xs,
return BitBucket;
} else {
++failures;
fprintf(stderr, "%s:%d: FAIL %s[0x%llx] %s %s[0x%llx]\n", file, line, xs, x,
fprintf(stderr, "%s:%d: FAIL: %s[0x%llx] %s %s[0x%llx]\n", file, line, xs, x,
rel, ys, y);
return PrintFailureDetails;
}