[ZScript] ToInt() not working with leading zero

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

[ZScript] ToInt() not working with leading zero

Post by gwHero »

When a string with numeric content is converted to an integer with ToInt(), the result is zero when the string has a leading zero.

Example:

Code: Select all

string s1 = "80";
string s2 = " 80";
string s3 = "080";
	
console.printf("%d", s1.ToInt());
console.printf("%d", s2.ToInt());
console.printf("%d", s3.ToInt());		
result:
80
80
0

Tested with recent devbuilds and latest official (3.2.1)
(.pk3 with example included)
Attachments
bugreport.pk3
(673 Bytes) Downloaded 18 times
User avatar
phantombeta
Posts: 2088
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: [ZScript] ToInt() not working with leading zero

Post by phantombeta »

This isn't a bug, technically - it's actually undocumented behaviour.
Basically, if you put a leading 0 before the number, it will interpret it as octal, since '0' is the prefix for octal.
And since the digits go from 0 to 7 in octal, it'll return 0, as "80" isn't a valid number in octal.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: [ZScript] ToInt() not working with leading zero

Post by gwHero »

Djeez.. I didn't know that (and absolutely didn't expect that).

But you're right. Testing with "70", " 70", "070" results in 70,70,56.

Okay,
call may be closed I suppose.
Post Reply

Return to “Closed Bugs [GZDoom]”