Re: [SLUG] big numbers

From: John Kiolbasa (john@kiolbasa.net)
Date: Wed Mar 31 2004 - 12:49:54 EST


Ronan Heffernan wrote:
> mrock wrote:
>
>> I have a program that analyses calls to phone numbers. (yes, this is the
>> same program that I have struggle with for some time now) The data file
>> is sorted on phone number (area code and the number) that makes it a 10
>> digit number. My comparisons fail at 2 to the 31st power. My last
>> phone number that works is 2147493101. 2 to the 31st power is
>> 2147483648. I think this is also the 2 Gbit limit I ran into in much
>> older systems. I am running RH 8.0.
>>
>>
>>
> This is probably not a 2GBit file limitation, but rather your numerical
> operations are using a signed-int (on linux, gcc treats 'int' and 'long'
> (and probably 'short') as 32-bits (at least this is the behavior on
> 32-bit architectures)). The fact that the int is 'signed' means that the
> possible range of values is approximately negative 2.1 billion through
> positive 2.1 billion. If you were able to tell BASH to use an 'unsigned
> int' then your range of values would become zero through apprx 4.2
> billion (which would still not work for you!) One thing that you might
> try is to add a ".0" to the end of your phone numbers to see if BASH
> will then treat them as 'float' numbers (twice the capacity?) I don't
> know if BASH will do float operations with -eq -lt -gt ? Maybe try it
> with a small sample file?
>
> If BASH can not be made to use higher-capacity variable types, you could
> use PERL, Python, C++, etc. (probably not the most welcome of answers.)
>

Floats would be worse - you would end up rounding off phone numbers
after the 7th or 8th digit. Bash, and the 'test' program I think are
reading the string names into 32-bit unsigned ints, like mentioned
above. You can of course check the source for test or bash and maybe
modify to read into a long long. Or implement your own phone-number
comparison program in the spirit of test. Then explicitly use this new
test command instead of '[' in your script. I checked the man and info
pages for test and couldn't find mention of max integer values for the
numeric comparisons.

Note that 'test' is usually symlinked to '[', I imagine to provide
support for shells that don't support the [] bracketed conditions.

-- 
John Kiolbasa
john@kiolbasa.net
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:51:08 EDT