changeset 29060:b1b09b88585a

ode15: Detect time events when time is a multiple of the output step size (bug #59063). * __ode15__.cc (IDA::event): Detect events when passing through or detaching from zero.
author Markus Meisinger <chloros2@gmx.de>
date Fri, 13 Nov 2020 08:31:12 +0100
parents b211e6e866f6
children 8a425e771aa7
files libinterp/dldfcn/__ode15__.cc
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__ode15__.cc	Fri Nov 13 19:27:05 2020 +0100
+++ b/libinterp/dldfcn/__ode15__.cc	Fri Nov 13 08:31:12 2020 +0100
@@ -786,8 +786,14 @@
         // Get the index of the changed values
         for (octave_idx_type i = 0; i < val.numel (); i++)
           {
-            if ((val(i) > 0 && oldval(i) < 0 && dir(i) != -1) // increasing
-                || (val(i) < 0 && oldval(i) > 0 && dir(i) != 1)) // decreasing
+            // Check for sign change and whether a rising / falling edge
+            // either passes through zero or detaches from zero (bug #59063)
+            if ((dir(i) != -1
+                 && ((val(i) >= 0 && oldval(i) < 0)
+                     || (val(i) > 0 && oldval(i) <= 0))) // increasing
+                || (dir(i) != 1
+                    && ((val(i) <= 0 && oldval(i) > 0)
+                        || (val(i) < 0 && oldval(i) >= 0)))) // decreasing
               {
                 index.resize (index.numel () + 1);
                 index (index.numel () - 1) = i;