[Top][All Lists]

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

[bug #58531] Analysis of (+loop)

From: Reuben Thomas
Subject: [bug #58531] Analysis of (+loop)
Date: Tue, 9 Jun 2020 04:31:48 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:77.0) Gecko/20100101 Firefox/77.0


                 Summary: Analysis of (+loop)
                 Project: Gforth
            Submitted by: rrt
            Submitted on: Tue 09 Jun 2020 08:31:47 AM UTC
                Category: None
                Severity: 3 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any



http://git.savannah.gnu.org/cgit/gforth.git/tree/prim#n374 has a comment "!!
check this thoroughly". Yesterday, I studied this code with a friend because
we found a bug in similar code I wrote dating back nearly 30 years, and it
turned out that my code's problem was precisely missing out one of the cases
which GForth's implementation covers. We believe the GForth code is correct.


Consider the cases for n>=0 and n<0 separately, then the code is equivalent to
the following:

Cell olddiff = n1-nlimit;
Cell newdiff = n2-nlimit;
if ((n >= 0) ? (
    olddiff < 0 && newdiff >=0
) : (
    olddiff >=0 && newdiff < 0
)) { ... }

In other words, we exit the loop if olddiff and newdiff have opposite sign and
olddiff and n have opposite sign.

Would it be useful to have the above, or something similar, as a comment to
replace "!! check this thoroughly"?

Anyway, thanks for this code, and for Anton's note on
https://forth-standard.org/standard/core/PlusLOOP that pointed us to it!


Reply to this item at:


  Message sent via Savannah

reply via email to

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