[v3.3] Negative numbers ?

Pixilang programming language
Post Reply
User avatar
spiny
Posts: 46
Joined: Mon Jul 19, 2010 4:28 pm

[v3.3] Negative numbers ?

Post by spiny »

this is probably me being a bit daft, but I am getting odd results when trying to work with negative numbers in v3.3 , for example:

Code: Select all

a=10
b=20
c=a-b
gives the value of c as 4294967286 rather than what I expected, -10

do I have to declare a container type somewhere ?

cheers :)
User avatar
NightRadio
Site Admin
Posts: 3944
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: [v3.3] Negative numbers ?

Post by NightRadio »

How did you get this number? Via sprintf? Please show this piece of code
User avatar
spiny
Posts: 46
Joined: Mon Jul 19, 2010 4:28 pm

Re: [v3.3] Negative numbers ?

Post by spiny »

this is the code to show the result:

Code: Select all

// subtrtaction test


a=10.0
b=20.0

c = (a-b)

start:
sprintf (result01, "RESULT:%u", c)
print(result, 0,0)

frame()
go start
also, what does the %u do in the sprintf function ? if I leave it out, the variable 'c' isn't shown.
Is there a better way to print a variable on screen ? using something like:

print (c,0,0)

doesn't seem to work.

cheers, Phil :)
User avatar
NightRadio
Site Admin
Posts: 3944
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: [v3.3] Negative numbers ?

Post by NightRadio »

%u - unsigned integer :)
Try to use %d or %i - it is for signed numbers.
You can read full description here: http://www.cplusplus.com/reference/clib ... io/printf/
User avatar
spiny
Posts: 46
Joined: Mon Jul 19, 2010 4:28 pm

Re: [v3.3] Negative numbers ?

Post by spiny »

NightRadio wrote:%u - unsigned integer :)
Try to use %d or %i - it is for signed numbers.
You can read full description here: http://www.cplusplus.com/reference/clib ... io/printf/
ah, that would make sense :)

As you can tell, I'm not much of a coder :D :D

thanks :)
User avatar
NightRadio
Site Admin
Posts: 3944
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: [v3.3] Negative numbers ?

Post by NightRadio »

No problem. Any questions are very useful for Pixilang community and its development.
Also taking into account, that Pixilang documentation is still not complete.
Post Reply