[flang-commits] [PATCH] D115084: [flang] Fix folding of EXPONENT() intrinsic function

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Sat Dec 4 11:23:17 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe337dc8bfee0: [flang] Fix folding of EXPONENT() intrinsic function (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115084/new/

https://reviews.llvm.org/D115084

Files:
  flang/include/flang/Evaluate/real.h
  flang/test/Evaluate/folding07.f90


Index: flang/test/Evaluate/folding07.f90
===================================================================
--- flang/test/Evaluate/folding07.f90
+++ flang/test/Evaluate/folding07.f90
@@ -197,6 +197,14 @@
   logical, parameter :: test_tiny10 = tiny10 == ztiny10
   logical, parameter :: test_tiny16 = tiny16 == ztiny16
 
+  logical, parameter :: test_exponent_0 = exponent(0.0) == 0
+  logical, parameter :: test_exponent_r8 = exponent(0.125) == -2
+  logical, parameter :: test_exponent_r4 = exponent(0.25) == -1
+  logical, parameter :: test_exponent_r2 = exponent(0.5) == 0
+  logical, parameter :: test_exponent_1 = exponent(1.0) == 1
+  logical, parameter :: test_exponent_4 = exponent(4.1) == 3
+  logical, parameter :: test_exponent_12 = exponent(12.9) == 4
+
   integer, parameter :: &
     max2 = maxexponent(0._2), &
     max3 = maxexponent(0._3), &
Index: flang/include/flang/Evaluate/real.h
===================================================================
--- flang/include/flang/Evaluate/real.h
+++ flang/include/flang/Evaluate/real.h
@@ -125,8 +125,10 @@
   template <typename INT> constexpr INT EXPONENT() const {
     if (Exponent() == maxExponent) {
       return INT::HUGE();
+    } else if (IsZero()) {
+      return {0};
     } else {
-      return {UnbiasedExponent()};
+      return {UnbiasedExponent() + 1};
     }
   }
 
@@ -308,6 +310,8 @@
 
   // Extracts unbiased exponent value.
   // Corrects the exponent value of a subnormal number.
+  // Note that the result is one less than the EXPONENT intrinsic;
+  // UnbiasedExponent(1.0) is 0, not 1.
   constexpr int UnbiasedExponent() const {
     int exponent{Exponent() - exponentBias};
     if (IsSubnormal()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115084.391848.patch
Type: text/x-patch
Size: 1693 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20211204/54358e62/attachment.bin>


More information about the flang-commits mailing list