bash "let" barfs on addition

Karl F. Larsen klarsen1 at gmail.com
Thu Mar 12 22:29:10 UTC 2009


Cameron Hutchison wrote:
> =?UTF-8?B?RXZ1cmFhbjo64LSP4LS14LWC4LSw4LS+4LSo4LWN4oCNIA==?= <evuraan at gmail.com> writes:
>
>   
>> Seen this sort of behaviour before? :
>>     
>
>   
>> mybash:>  a="7540113804746346429"
>> mybash:>  b="4660046610375530309"
>> mybash:> let c=(a+b)
>> mybash:> echo $c
>> -6246583658587674878
>>     
>
> Both a and b are 63-bit numbers. It looks like bash is using signed
> 64-bit numbers for its arithmetic, as your arithmetic will overflow when
> performed with signed 64-bit numbers.
>
>
>   
    Yes it has to be too big numbers. On my Hardy it works fine with 
small numbers:

karl at karl-hardy:~$ a="3"
karl at karl-hardy:~$ b="6"
karl at karl-hardy:~$ let c=(a+b)
karl at karl-hardy:~$ echo $c
9


Karl


-- 

	Karl F. Larsen, AKA K5DI
	Linux User
	#450462   http://counter.li.org.
   PGP 4208 4D6E 595F 22B9 FF1C  ECB6 4A3C 2C54 FE23 53A7





More information about the ubuntu-users mailing list