octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #64692] colon range includes an extra value


From: Arun Giridhar
Subject: [Octave-bug-tracker] [bug #64692] colon range includes an extra value
Date: Fri, 22 Sep 2023 21:01:44 -0400 (EDT)

Follow-up Comment #23, bug #64692 (project octave):

I pushed the documentation edits on stable.

Re the code change, this is what I get:

octave:2> -2:0     # normal
ans =
  -2  -1   0

octave:3> -2 : (0.3 - 0.2 - 0.1)
warning: range limit is not an integer and will not be reached exactly
ans =
  -2  -1   0

octave:6> 1.8 : 0.05 : 1.9
warning: using floating point values in range may yield unexpected results
ans =
    1.8000    1.8500    1.9000

octave:7> 1.85 : 0.05 : 1.9       #  MISSED WARNING!
ans = 1.8500


How do I fix that last missed warning? Evidently the fact that it has only one
element somehow makes it return early but I'm not sure yet which early path it
takes...

Here's the code change so far:


diff -r 9d758cacf7ca libinterp/corefcn/interpreter.cc
--- a/libinterp/corefcn/interpreter.cc  Fri Sep 22 20:28:30 2023 -0400
+++ b/libinterp/corefcn/interpreter.cc  Fri Sep 22 20:59:53 2023 -0400
@@ -2084,6 +2084,8 @@ void interpreter::maximum_braindamage ()
 
   m_error_system.disable_warning ("Octave:abbreviated-property-match");
   m_error_system.disable_warning ("Octave:colon-nonscalar-argument");
+  m_error_system.disable_warning ("Octave:floating-point-limit-in-range");
+  m_error_system.disable_warning ("Octave:floating-point-in-range");
   m_error_system.disable_warning ("Octave:data-file-in-path");
   m_error_system.disable_warning ("Octave:empty-index");
   m_error_system.disable_warning ("Octave:function-name-clash");
diff -r 9d758cacf7ca liboctave/array/Range.cc
--- a/liboctave/array/Range.cc  Fri Sep 22 20:28:30 2023 -0400
+++ b/liboctave/array/Range.cc  Fri Sep 22 20:59:53 2023 -0400
@@ -249,6 +249,17 @@ xinit (T base, T limit, T inc, bool reve
       return;
     }
 
+  // Warn about floating point values in ranges.
+  if (math::nint_big (base) == base && math::nint_big (inc) == inc
+      && math::nint_big (limit) != limit)
+    (*current_liboctave_warning_with_id_handler)
+      ("Octave:floating-point-limit-in-range",
+       "range limit is not an integer and will not be reached exactly");
+  else if (math::nint_big (base) != base || math::nint_big (inc) != inc)
+    (*current_liboctave_warning_with_id_handler)
+      ("Octave:floating-point-in-range",
+       "using floating point values in range may yield unexpected results");
+
   // Now that we have handled all the special cases, we can compute
   // the number of elements and the final value in a way that attempts
   // to avoid rounding errors as much as possible.




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?64692>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]