[flang-commits] [flang] b7585c7 - [flang][runtime] Fix NORM2([negative, ...])

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Jul 21 14:57:46 PDT 2023


Author: Peter Klausler
Date: 2023-07-21T14:57:31-07:00
New Revision: b7585c75eeaf58f7602c1310f14e8e63b5501845

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

LOG: [flang][runtime] Fix NORM2([negative, ...])

NORM2 is broken for arrays that start with a negative number
because it sets the initial running max_ value to that number
rather than to its absolute value.

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

Added: 
    

Modified: 
    flang/runtime/extrema.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/extrema.cpp b/flang/runtime/extrema.cpp
index c9dcc65bba6b87..d02cf46a6f3b88 100644
--- a/flang/runtime/extrema.cpp
+++ b/flang/runtime/extrema.cpp
@@ -800,7 +800,7 @@ template <int KIND> class Norm2Accumulator {
   bool Accumulate(Type x) {
     auto absX{std::abs(static_cast<AccumType>(x))};
     if (!max_) {
-      max_ = x;
+      max_ = absX;
     } else if (absX > max_) {
       auto t{max_ / absX}; // < 1.0
       auto tsq{t * t};


        


More information about the flang-commits mailing list