[flang] Fold SPACING() correctly when result is subnormal

The intrinsic function SPACING() was being folded to the smallest
normal number (TINY(x)) rather than to a smaller subnormal result
when that result really was subnormal.

Differential Revision: https://reviews.llvm.org/D132155
This commit is contained in:
Peter Klausler 2022-08-12 13:20:08 -07:00
parent 6fed13f502
commit 92afe80213
2 changed files with 3 additions and 2 deletions

View File

@ -749,8 +749,7 @@ template <typename W, int P> Real<W, P> Real<W, P>::SPACING() const {
return TINY();
} else {
Real result;
result.Normalize(
false, Exponent() - binaryPrecision + 1, Fraction::MASKL(1));
result.Normalize(false, Exponent(), Fraction::MASKR(1));
return result;
}
}

View File

@ -5,6 +5,8 @@ module m
logical, parameter :: test_2 = spacing(-3.0) == scale(1.0, -22)
logical, parameter :: test_3 = spacing(3.0d0) == scale(1.0, -51)
logical, parameter :: test_4 = spacing(0.) == tiny(0.)
logical, parameter :: test_5 = spacing(tiny(0.)) == 1.e-45
logical, parameter :: test_6 = spacing(8388608.) == 1.
logical, parameter :: test_11 = rrspacing(3.0) == scale(0.75, 24)
logical, parameter :: test_12 = rrspacing(-3.0) == scale(0.75, 24)
logical, parameter :: test_13 = rrspacing(3.0d0) == scale(0.75, 53)