forked from OSchip/llvm-project
[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:
parent
3fb4757cc7
commit
99c23c1a92
|
@ -123,28 +123,31 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename INT> constexpr ValueWithRealFlags<INT> ToInteger() const {
|
template<typename INT> constexpr ValueWithRealFlags<INT> ToInteger() const {
|
||||||
ValueWithRealFlags<INT> result;
|
|
||||||
bool isNegative{IsNegative()};
|
bool isNegative{IsNegative()};
|
||||||
std::uint64_t exponent{Exponent()};
|
std::uint64_t exponent{Exponent()};
|
||||||
Fraction fraction{GetFraction()};
|
Fraction fraction{GetFraction()};
|
||||||
|
ValueWithRealFlags<INT> result;
|
||||||
if (exponent == maxExponent && !fraction.IsZero()) { // NaN
|
if (exponent == maxExponent && !fraction.IsZero()) { // NaN
|
||||||
result.flags.set(RealFlag::InvalidArgument);
|
result.flags.set(RealFlag::InvalidArgument);
|
||||||
result.value = result.value.HUGE();
|
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) {
|
if (isNegative) {
|
||||||
result.value = result.value.MASKL(1);
|
result.value = result.value.MASKL(1);
|
||||||
} else {
|
} else {
|
||||||
result.value = result.value.HUGE();
|
result.value = result.value.HUGE();
|
||||||
}
|
}
|
||||||
result.flags.set(RealFlag::Overflow);
|
result.flags.set(RealFlag::Overflow);
|
||||||
} else if (exponent < exponentBias) { // |x| < 1.0
|
} else if (exponent < exponentBias) { // |x| < 1.0 -> 0
|
||||||
if (!fraction.IsZero()) {
|
if (!fraction.IsZero()) {
|
||||||
result.flags.set(RealFlag::Underflow);
|
result.flags.set(RealFlag::Underflow);
|
||||||
result.flags.set(RealFlag::Inexact);
|
result.flags.set(RealFlag::Inexact);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (exponent < exponentBias + significandBits) {
|
// finite number |x| >= 1.0
|
||||||
int rshift = exponentBias + significandBits - exponent;
|
constexpr std::uint64_t noShiftExponent{exponentBias + precision - 1};
|
||||||
|
if (exponent < noShiftExponent) {
|
||||||
|
int rshift = noShiftExponent - exponent;
|
||||||
if (!fraction.IBITS(0, rshift).IsZero()) {
|
if (!fraction.IBITS(0, rshift).IsZero()) {
|
||||||
result.flags.set(RealFlag::Inexact);
|
result.flags.set(RealFlag::Inexact);
|
||||||
}
|
}
|
||||||
|
@ -155,7 +158,7 @@ public:
|
||||||
result.value = truncated.value;
|
result.value = truncated.value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int lshift = exponent - (exponentBias + significandBits);
|
int lshift = exponent - noShiftExponent;
|
||||||
if (lshift + precision >= result.value.bits) {
|
if (lshift + precision >= result.value.bits) {
|
||||||
result.flags.set(RealFlag::Overflow);
|
result.flags.set(RealFlag::Overflow);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -43,7 +43,7 @@ FailureDetailPrinter Test(
|
||||||
return BitBucket;
|
return BitBucket;
|
||||||
} else {
|
} else {
|
||||||
++failures;
|
++failures;
|
||||||
fprintf(stderr, "%s:%d: FAIL %s\n", file, line, predicate);
|
fprintf(stderr, "%s:%d: FAIL: %s\n", file, line, predicate);
|
||||||
return PrintFailureDetails;
|
return PrintFailureDetails;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ FailureDetailPrinter Compare(const char *file, int line, const char *xs,
|
||||||
return BitBucket;
|
return BitBucket;
|
||||||
} else {
|
} else {
|
||||||
++failures;
|
++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);
|
rel, ys, y);
|
||||||
return PrintFailureDetails;
|
return PrintFailureDetails;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue