[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:06:27 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) {
----------------
ejose02 wrote:

Fixed for constant folding: compute the direct path first and only retry with 1/base when RealFlag::Overflow is set (and negative exponent, |base| > 1). Ordinary powers like 3**(-2) keep the previous rounded value.

https://github.com/llvm/llvm-project/pull/205262


More information about the flang-commits mailing list