Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unsigned integers
#1
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.
ean Debord
----------------
Math library for FreeBasic:
http://www.unilim.fr/pages_perso/jean.de...fbmath.zip
Reply
#2
This works:
Code:
DIM K AS UInteger
K = 1500000000 + 1000000000
? K
sleep

cu, helpy
Reply
#3
Code:
a=2500000000u
does not work
Code:
a=2500000000u&
does not work either
Antoni
Reply
#4
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
Reply
#5
Thanks. I will wait for the new version Smile
ean Debord
----------------
Math library for FreeBasic:
http://www.unilim.fr/pages_perso/jean.de...fbmath.zip
Reply
#6
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..
Reply
#7
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.
ean Debord
----------------
Math library for FreeBasic:
http://www.unilim.fr/pages_perso/jean.de...fbmath.zip
Reply
#8
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..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)