Integer Size Limit?

Howdy!

I have a script that iterates through the database file structure on the server's hard disk to calculate the disk space occupied by each module in the current project (script is run from database explorer). It reports the total module size and module ID (e.g., 000009a2). When it is done with all of the modules, it is supposed to report the size of the entire project, which has been calculated by adding the size of each successive module's directory. It seems to work fine until I use it on a project that is "too big," at which point it reports the final project size as a negative number.

All numbers are integers, which represent the number of bytes. For example, I have a project whose module sizes add up to 3856838853 (~3.6GB), but the number reported by the script is -438128443.

I only have a handful of projects at my disposal, so the limited data points available to me say that the "too big" threshold appears to be between ~2.0GB and ~2.6GB

Could this be an odometer-turning-over kind of issue?

Thanks,
Bill
SystemAdmin - Mon Jun 11 18:05:12 EDT 2012

Re: Integer Size Limit?
Mathias Mamsch - Tue Jun 12 04:35:40 EDT 2012

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"

 


However the smarter way would probably be to just use a 'real' variable :-) Maybe that helps, regards Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Integer Size Limit?
SystemAdmin - Wed Jun 20 15:38:52 EDT 2012

Best solution for my script is to adapt it to use reals. Thanks for the answer, insight, and sample code.