changeset 21275:85d8280c64f4

Return NaN for norm (..., +/-Inf) if input contains NaN (bug #32855). * oct-norm.cc (norm_accumulator_inf::accum, norm_accumulator_minf::accum): Use xisnan to check for NaN value before continuing to accumulate.
author Rik <rik@octave.org>
date Tue, 16 Feb 2016 16:01:56 -0800
parents bc536eff5eab
children 3b4bb843ffcd
files liboctave/numeric/oct-norm.cc
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/numeric/oct-norm.cc	Tue Feb 16 14:47:35 2016 -0500
+++ b/liboctave/numeric/oct-norm.cc	Tue Feb 16 16:01:56 2016 -0800
@@ -179,7 +179,10 @@
   template <typename U>
   void accum (U val)
   {
-    max = std::max (max, std::abs (val));
+    if (xisnan (val))
+      max = octave_NaN;
+    else
+      max = std::max (max, std::abs (val));
   }
   operator R () { return max; }
 };
@@ -194,7 +197,10 @@
   template <typename U>
   void accum (U val)
   {
-    min = std::min (min, std::abs (val));
+    if (xisnan (val))
+      min = octave_NaN;
+    else
+      min = std::min (min, std::abs (val));
   }
   operator R () { return min; }
 };