Posts: 60
Threads: 8
Joined: Jan 2005
Which suffix must be appended to a number to force it as an unsigned integer?
Code:
DIM K AS UINTEGER
K = 2500000000
? K
Output is 2147483648. Seems that K is converted to a signed integer.
Posts: 21
Threads: 3
Joined: Dec 2004
This works:
Code:
DIM K AS UInteger
K = 1500000000 + 1000000000
? K
sleep
cu, helpy
Posts: 1,407
Threads: 117
Joined: Dec 2002
does not work
does not work either
Antoni
Posts: 21
Threads: 3
Joined: Dec 2004
test with the current CVS version of FB:
Code:
DIM K AS UInteger
K = 2500000000 ' does not work
? K
K = 2500000000u ' does work !!!
? K
sleep
cu, helpy
Posts: 60
Threads: 8
Joined: Jan 2005
Thanks. I will wait for the new version
Posts: 922
Threads: 15
Joined: Jun 2003
Yeah, at the moment you have to use a suffix to tell the compiler it's an unsigned number (as in C).
Without a suffix that should also work, but i will have to implement a "special" VAL() for integers only (VAL() returns a DOUBLE), because the compiler itself uses VAL() to convert the token literal from a string to a value.
Below the (really lastest) 0.13, operations with unsigned literals above 2^31 would fail too, as everything was done with DOUBLE's internally, but unsigned int's above 2^31 will be saturated by the x86 FPU when doing a conversion, so now internally double's are used only with floating-point literals, or if using constants in floating-point operations.
EDIT: VALINT() added, with or without suffixes the unsigned constants above 2^31 won't be saturated anymore.. wait for the next release, because there will be a chicken-egg problem, as the compiler itself is using valint() is many parts now..
Posts: 60
Threads: 8
Joined: Jan 2005
Yes it works with 0.13b (just downloaded). Thank you very much!
But I have another question: how can I use 64-bit integers? which is the type name / suffix? I found nothing in the docs.
EDIT: The type name is ULONGINT. I should have guessed :oops:
But what is the suffix? 'UL' seems to be for unsigned 32 bit integer.
Posts: 922
Threads: 15
Joined: Jun 2003
Yeah, UL is for 32-bit unsigned int's. ULL is for 64-bit unsigned long ints.. i'm ran out of suffixes.. using ?? && %% makes the code look like spaghetti..