[flang-commits] [flang] [llvm] [flang] Fix wrong result for exponentiation when denormal is expected (PR #205262)
via flang-commits
flang-commits at lists.llvm.org
Fri Oct 9 05:04:00 PDT 2026
================
@@ -51,6 +55,23 @@ ValueWithRealFlags<REAL> TimesIntPowerOf(const REAL &factor, const REAL &base,
return result;
}
+template <typename W, int P, typename INT>
+ValueWithRealFlags<value::Real<W, P>> IntPower(const value::Real<W, P> &base,
+ const INT &power,
+ Rounding rounding = TargetCharacteristics::defaultRounding) {
+ using REAL = value::Real<W, P>;
+ REAL one{REAL::FromInteger(INT{1}).value};
+ if (power.IsNegative() && !base.IsZero() &&
+ base.ABS().Compare(one) == Relation::Greater) {
+ ValueWithRealFlags<REAL> result;
+ REAL recip{one.Divide(base, rounding).AccumulateFlags(result.flags)};
+ result.value = TimesIntPowerOf(one, recip, power.ABS().value, rounding)
----------------
ejose02 wrote:
Fixed: on overflow retry we pass the original power with forceMultiply so we don’t treat INT_MIN magnitude as a negative exponent again and invert the result.
https://github.com/llvm/llvm-project/pull/205262
More information about the flang-commits
mailing list