FAQ  •  Register  •  Login

byte loops (*solved*)

<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Thu Apr 19, 2012 1:50 am

byte loops (*solved*)

This seems to not work - skipping the loop. Surely small negative numbers shouldn't be an issue for a byte sized variable?

  Code:
DIM x as byte

for x=-91 to 91
print x
next x
<<

LCD

Posts: 507

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Thu Apr 19, 2012 8:29 am

Re: byte loops

Confirmed!Also if the loop is from -1 to 91, it exits at 70!!! This is abnormal.
Forget what I said, I forgot that in ZXBC print does not scroll but starts from top of scereen again, ovberwriting old text, I just saw "70" as lowest number :oops:
Last edited by LCD on Thu Apr 19, 2012 2:44 pm, edited 1 time in total.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1146

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu Apr 19, 2012 9:05 am

Re: byte loops

Hmm. This is a Serious bug, considering we (yes, you and me :P) extensively tested this during the type-migration from 1.2.6 to 1.2.8.
Will check this tonight!

Meanwhile: Can you check it with Integer and Long types? :-| I guess this is a wrong (unsigned) conversion for byte types.
<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Thu Apr 19, 2012 9:39 am

Re: byte loops

boriel wrote:Meanwhile: Can you check it with Integer and Long types? :-| I guess this is a wrong (unsigned) conversion for byte types.


I think I tested integer, and that worked, last night. I'll try to find time to squeeze some tests in, but busy at the moment :)
<<

LCD

Posts: 507

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Thu Apr 19, 2012 3:00 pm

Re: byte loops

My experiments:
  Code:
DIM x as byte

for x=-36 to 91
print x;" , ";
next x

Works well, but if startts wits -37:
  Code:
DIM x as byte

for x=-37 to 91
print x;" , ";
next x

It does not work anymore, so 37 is a magic number.
  Code:
DIM x as Integer

for x=-20000 to 20000
print x;" , ";
next x

did not work too.
  Code:
DIM x as Integer

for x=-15000 to 15000
print x;" , ";
next x

Works well
  Code:
DIM x as Long

for x=-1100000000 to 1100000000
print x;" , ";
next x

does not work
  Code:
DIM x as Long

for x=-1000000000 to 1000000000
print x;" , ";
next x

Works

  Code:
DIM x as byte

for x=-91 to 36
print x;" , ";
next x

Works
  Code:
DIM x as byte

for x=-91 to 37
print x;" , ";
next x

DOES NOT WORK!!! :shock:
OMG, how it can be?
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Thu Apr 19, 2012 4:01 pm

Re: byte loops

Interesting.

Looks to me as though it's an issue if the gap from start -> end is greater than the range of the variable that's holding them....

ie bigger than 128 for a byte
or 32767 for an integer.
<<

LCD

Posts: 507

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Fri Apr 20, 2012 6:56 am

Re: byte loops

Sounds logical, but it means a complete rewrite of the FOR NEXT Routine for signed types. I wonder if a loop 20 TO 140 would work with BYTE type... I'm not at home to test it...
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1146

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Fri Apr 20, 2012 7:37 am

Re: byte loops

britlion wrote:Interesting.

Looks to me as though it's an issue if the gap from start -> end is greater than the range of the variable that's holding them....

ie bigger than 128 for a byte
or 32767 for an integer.

It's exactly that (after debugging yesterday night). Basically, when end - start overflows.
This is not a bug in for, but (again :!:) with relational operators ("comparators") for signed values, so (a < b) for signed should fail also. It seems a regression bug when reintroduced in 1.2.8 after the "hard refactorization II".
<<

boriel

Site Admin

Posts: 1146

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Fri Apr 20, 2012 11:56 pm

Re: byte loops

Okay: This is a *dangerous* bug. It happened will operators <, <=, >, >= for signed (Byte, Integer and probably Long) types.
Currently, only Long has not been tested (and fixed). So please, please, download and check it now, the new version 1.2.9s841 and tell me.
<<

LCD

Posts: 507

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Sat Apr 21, 2012 8:48 am

Re: byte loops

boriel wrote:Okay: This is a *dangerous* bug. It happened will operators <, <=, >, >= for signed (Byte, Integer and probably Long) types.
Currently, only Long has not been tested (and fixed). So please, please, download and check it now, the new version 1.2.9s841 and tell me.

Okay, BYTE and INTEGER types works now, LONG does not work.
  Code:
dim x as long
x=-2000000000
if x<1900000000 then print "okay":end If

did not work too.
It is not "dangerous", I'm still alive ( :D ) even after testing it. But it was a serius bug.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1146

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun Apr 22, 2012 12:50 am

Re: byte loops

Well, I meant not only serious, but highly probable to happen (specially for byte types). Also Fixed types where affected (they are compared as Long's). It also might affect correctly written programs (specially games) compiled in the past! :( So the "danger" resides in some ZX Basic contests I've seen in some webs.

I think it's already fixed. Please, try 1.2.9s852 and tell me?
<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sun Apr 22, 2012 9:33 am

Re: byte loops

Yes - this update fixed this. This program depends upon loops from -x+median to x+median.

The question now is how to get it faster. The slowest part is generating a random number for each pixel - but each time I've tried a rough and ready faster rnd, it makes it look awful :)
Attachments
Planet.tzx
(1.73 KiB) Downloaded 36 times
<<

boriel

Site Admin

Posts: 1146

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun Apr 22, 2012 10:14 am

Re: byte loops

Whoa! ZX Spectrum Rendering! :shock: It will always run slow :D.
Are you using Floats or Fixeds? Also, the RND is already optimized and produces a better random pattern than the ZX Spectrum one. You should perhaps try a random Stream generator? (I've used in cryptography: http://en.wikipedia.org/wiki/Stream_cipher random bit generator?)
<<

britlion

Posts: 679

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Mon May 28, 2012 10:22 pm

Re: byte loops (*solved*)

And in fact, if I try the xor-shift generator ( post2853.html?hilit=random#p2853 ) it finishes in 19 seconds, instead of 48...
<<

boriel

Site Admin

Posts: 1146

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon May 28, 2012 10:42 pm

Re: byte loops (*solved*)

Yes, I overlooked the stream rnd generator. Hmmm. Too many things to include in the library!
Can you plot RND * 256, RND * 192 for about... let's say 10.000 iterations, and compare the ZX Basic RND and yours?
ZX Basic is really good, but not as fast as this one, since it uses ULong (32 bit x 32 bit = 64 bit) multiplication!
Next

Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO