diff liboctave/util/lo-array-errwarn.cc @ 25807:cb775c73866d

Don't print fractional part of an invalid NaN index. * lo-array-errwarn.cc (err_invalid_index): Use std::isnan to determine number is regular before checking if it has a fractional part to print. * index.tst: Use Octave convention for comments ('#', not '%'). Add bug numbers to %!tests.
author Rik <rik@octave.org>
date Thu, 16 Aug 2018 16:30:26 -0700
parents 0360ed7c39a8
children 00f796120a6d
line wrap: on
line diff
--- a/liboctave/util/lo-array-errwarn.cc	Thu Jan 14 14:03:17 2016 +1100
+++ b/liboctave/util/lo-array-errwarn.cc	Thu Aug 16 16:30:26 2018 -0700
@@ -217,10 +217,14 @@
   {
     std::ostringstream buf;
     buf << n + 1;
-    // if  n  not an integer, but would be printed as one, show diff
-    double nearest = std::floor (n + 1.5);
-    if (n + 1 != nearest && (buf.str ().find ('.') == std::string::npos))
-      buf << std::showpos << (n + 1 - nearest);
+
+    if (! std::isnan (n))
+      {
+        // if  n  not an integer, but would be printed as one, show diff
+        double nearest = std::floor (n + 1.5);
+        if (n + 1 != nearest && (buf.str ().find ('.') == std::string::npos))
+          buf << std::showpos << (n + 1 - nearest);
+      }
 
     err_invalid_index (buf.str (), nd, dim, var);
   }