bugGforth - Bugs: bug #58531, Analysis of (+loop)

 
 

bug #58531: Analysis of (+loop)

Submitter:  Reuben Thomas <rrt>
Submitted:  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:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 16 Aug 2020 09:45:42 AM UTC, comment #2: 

Thanks for the analysis.

The comment about gforth-native is still relevant, because it explains the original reason for using (...&...)>=0 instead of ...>=0 || ...>=0; that reason is no longer very relevant, so we may change this decision.

Anton Ertl <anton>
Group administrator
Tue 09 Jun 2020 09:38:02 AM UTC, comment #1: 

Also, a comment in the code at line 381 mentions gforth-native, which is defunct; presumably therefore that comment should be removed?

Reuben Thomas <rrt>
Tue 09 Jun 2020 08:31:47 AM UTC, original submission:  

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!

Reuben Thomas <rrt>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by anton (Posted a comment)
  • -email is unavailable- added by rrt (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-08-16 anton Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code