[flang-commits] [flang] 1e954a1 - [flang] Fix off-by-one results from folding MAXEXPONENT and MINEXPONENT

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Nov 18 09:04:12 PST 2021


Author: Peter Klausler
Date: 2021-11-18T09:04:04-08:00
New Revision: 1e954a1c6678d315ae233f4141fa3ed8f0d9d122

URL: https://github.com/llvm/llvm-project/commit/1e954a1c6678d315ae233f4141fa3ed8f0d9d122
DIFF: https://github.com/llvm/llvm-project/commit/1e954a1c6678d315ae233f4141fa3ed8f0d9d122.diff

LOG: [flang] Fix off-by-one results from folding MAXEXPONENT and MINEXPONENT

Every one was too low by one.

Differential Revision: https://reviews.llvm.org/D114027

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Evaluate/real.h b/flang/include/flang/Evaluate/real.h
index b6c313c0057c5..80e677780db40 100644
--- a/flang/include/flang/Evaluate/real.h
+++ b/flang/include/flang/Evaluate/real.h
@@ -150,8 +150,8 @@ class Real : public common::RealDetails<PREC> {
   static constexpr int DIGITS{binaryPrecision};
   static constexpr int PRECISION{Details::decimalPrecision};
   static constexpr int RANGE{Details::decimalRange};
-  static constexpr int MAXEXPONENT{maxExponent - 1 - exponentBias};
-  static constexpr int MINEXPONENT{1 - exponentBias};
+  static constexpr int MAXEXPONENT{maxExponent - exponentBias};
+  static constexpr int MINEXPONENT{2 - exponentBias};
 
   constexpr Real FlushSubnormalToZero() const {
     if (IsSubnormal()) {

diff  --git a/flang/test/Evaluate/folding07.f90 b/flang/test/Evaluate/folding07.f90
index 9d9d4e9ee6b5d..e79dfaf9d4563 100644
--- a/flang/test/Evaluate/folding07.f90
+++ b/flang/test/Evaluate/folding07.f90
@@ -204,12 +204,12 @@ module m
     max8 = maxexponent(0._8), &
     max10 = maxexponent(0._10), &
     max16 = maxexponent(0._16)
-  logical, parameter :: test_max2 = max2 == 15
-  logical, parameter :: test_max3 = max3 == 127
-  logical, parameter :: test_max4 = max4 == 127
-  logical, parameter :: test_max8 = max8 == 1023
-  logical, parameter :: test_max10 = max10 == 16383
-  logical, parameter :: test_max16 = max16 == 16383
+  logical, parameter :: test_max2 = max2 == 16
+  logical, parameter :: test_max3 = max3 == 128
+  logical, parameter :: test_max4 = max4 == 128
+  logical, parameter :: test_max8 = max8 == 1024
+  logical, parameter :: test_max10 = max10 == 16384
+  logical, parameter :: test_max16 = max16 == 16384
 
   integer, parameter :: &
     min2 = minexponent(0._2), &
@@ -218,12 +218,12 @@ module m
     min8 = minexponent(0._8), &
     min10 = minexponent(0._10), &
     min16 = minexponent(0._16)
-  logical, parameter :: test_min2 = min2 == -14
-  logical, parameter :: test_min3 = min3 == -126
-  logical, parameter :: test_min4 = min4 == -126
-  logical, parameter :: test_min8 = min8 == -1022
-  logical, parameter :: test_min10 = min10 == -16382
-  logical, parameter :: test_min16 = min16 == -16382
+  logical, parameter :: test_min2 = min2 == -13
+  logical, parameter :: test_min3 = min3 == -125
+  logical, parameter :: test_min4 = min4 == -125
+  logical, parameter :: test_min8 = min8 == -1021
+  logical, parameter :: test_min10 = min10 == -16381
+  logical, parameter :: test_min16 = min16 == -16381
 
   integer, parameter :: &
     irange1 = range(0_1), &


        


More information about the flang-commits mailing list