SRL Archive - SRL Bugs

Value of Type: Byte


kazhual

2012-10-31 09:20:26

Today i was making a list of the Types that can be used and i got this weird thing.

A byte contains 8 bits.
That means the value should be between 0-255
Min: (2^0)-1 = 0
Max: (2^8)-1 = 255
But this is definitely exceeded since i can do this:

program Variables;
{$DEFINE SMART}

var
example : Byte ;

begin
example := 1944670000000000000000000 ;

end.

Compiled successfully in 15 ms.
Successfully executed.

riwu

2012-10-31 09:23:17

Yes you can do that but it will result in integer overflow, meaning that it will start counting from start again. Eg. 255=255, 256=0, 257=1..and the cycle repeats.

If you do writeln(example) it will not return any value higher than 255.

This is a common feature/problem in almost all processors. (and it has famously turned suomi to rank 1900+ when his total xp exceeded the maximum integer of unsigned 32 bit)

weequ

2012-10-31 09:27:14

Actually it just seems to return 0 when set to hundreds of billions.

riwu

2012-10-31 09:31:39

From: weequ
Actually it just seems to return 0 when set to hundreds of billions.

Nope, you are just lucky enough (1/256 chance) to hit the 0th number, try increasing it by a bit.

EDIT: oh you are right, it turns 0 when the number of digits exceed 19. Maybe that's just because Simba can't handle it.

slushpuppy

2012-10-31 10:19:25

Good read for newbies

http://en.wikipedia.org/wiki/Integer_overflow

kazhual

2012-10-31 10:32:07

I just did not expect an overflow but the error that it is out of range, like HEX better for such things