Howdy! |
Re: Integer Size Limit?
DXL uses signed 32 bit integers giving you a range from -2147483648 to 2147483647. If you need larger integers you need to work around that somehow. I guess the easiest way for you would be to treat the 32 bit integers as unsigned integers, which will allow you to go from 0 to 4294967295. For this you would need to have a function that converts the unsigned integer to a decimal representation:
string stringAdd (string a, string b) {
int i;
int aLen = length a
int bLen = length b
// make sure that b is the larger one
if (aLen > bLen) {
string cs = b; b = a; a = cs
int ci = bLen; bLen = aLen; aLen = ci
}
// pad a with zeros
for (i = 0; i < bLen-aLen; i++) a = "0" a
// now add the digits
string result = ""
int carry = 0
for (i = bLen-1; i >= 0; i--) {
int dig = (intOf a[i] "") + (intOf b[i] "") + carry
if (dig > 10) { carry = 1; dig = dig - 10 } else { carry = 0 }
result = dig result
}
return result
}
string unsigned (int a) {
// check if sign bit is set? If not just return the normal string
if (a >= 0) return a ""
// okay, we have a negative number, so get rid of the sign bit and then
// multiply by two 'manually' in a string.
// we have <sign> <... 30 bits ...> <low bit>
string s = (a & 0x7FFFFFFF) ""
return stringAdd (s, "2147483648")
}
int a = 0x7FFFFFFF
print "Largest Integer : " a "\n"
print "Largest Integer + 1 (signed) : " (a+1) "\n"
print "Largest Integer + 1 (unsigned): " (unsigned (a+1)) "\n"
print "Now we can go up to: " (unsigned (a * 2 + 1)) "\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Integer Size Limit? |