[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 |
URL:
<https://savannah.gnu.org/bugs/?58531>
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
_______________________________________________________
Details:
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.
Analysis:
Consider the cases for n>=0 and n<0 separately, then the code is equivalent to
the following:
Cell olddiff = n1-nlimit;
n2=n1+n;
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:
<https://savannah.gnu.org/bugs/?58531>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [bug #58531] Analysis of (+loop),
Reuben Thomas <=