Unsigned integers

DOS specific questions.
Post Reply
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Unsigned integers

Post by jdebord »

It seems that neither the DOS version nor the Linux version of FB can handle the unsigned long integers correctly.

See for instance the example program litnum_ops:

Code: Select all

	if( 4294967295UL + 10UL = 9UL ) then
		print 4294967295UL + 10UL; " = "; 9UL
	end if
		
	if( 4294967295UL > 2147483648UL ) then
		print 4294967295UL; " > "; 2147483648UL
	end if
	
	if( (1! or 2!) = 3 ) then
		print 1! or 2!; " ="; 1! or 2!
	end if	
		
	if( (1! shl 2!) = 4 ) then
		print 1! shl 2!; " ="; 1! shl 2!
	end if
	
	sleep
This bug existed in some previous Windows version but it has been corrected. Perhaps the DOS/Linux versions were not updated accordingly?
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Post by DrV »

I don't see the bug; with fbc 0.14, I get these results:

Code: Select all

C:\>fbc math.bas -target win32

C:\>math
9 = 9
4294967295 > 2147483648
 3 = 3
 4 = 4

C:\>fbc math.bas -target dos

C:\>math
9 = 9
4294967295 > 2147483648
 3 = 3
 4 = 4
Could you explain what the buggy behavior is?
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Post by DrV »

Hmm, compiling with the DOS compiler (rather than cross-compiling from Win32 fbc) results in this:

Code: Select all

C:\>fbc math.bas

C:\>math
 3 = 3
 4 = 4
Which is wrong, I suppose. :) So it's a bug in the compiler somewhere, not in the generated code...
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Post by jdebord »

Yes, the bug appears when using the compiler from the DOS or Linux versions. (I did not try to cross-compile with the Windows compiler).

It's a saturation problem: integers > 2147483648 are given the value 2147483648.

This problem was identified and solved in the Windows compiler. So it explains why the cross-compilation with the Windows compiler gives the correct results.
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Post by v1ctor »

Fixed, changes are in CVS, atoi() won't handle unsigned int literals above 2^31 in DOS or Linux, that seems to be a M$-only feature.
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Post by jdebord »

Thanks!
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Post by jdebord »

Thanks!
Post Reply