bash "let" barfs on addition

Matthew Flaschen matthew.flaschen at
Thu Mar 12 23:34:56 UTC 2009

Evuraan::ഏവൂരാന്‍ wrote:

> I know, I can use bc,dc,awk, python and even a desk calculator  wide
> enough :) - but, I am curious as to why is "let" letting us down?

First of all, it is nothing specific to let, as you can see from:

echo $((7540113804746346429+4660046610375530309))

Second, if you use the source (apt-get source, or just look at
you can see:

"All arithmetic is done as intmax_t integers with no checking for
overflow (though division by 0 is caught and flagged as an error)."

In this case, intmax_t is obviously a 64-bit signed two's complement
integer.  Your some exceeds that bound, hence the overflow into a
negative.  Now, if you're wondering "How come that's the limit?  Where
is it specified?" it /isn't/.  Math is not in the POSIX shell
so bash considers itself free to provide as much or as little as it

You are right to use bc if you crave more.  It is /documented/
( to
support arbitrary precision.

Matt Flaschen

More information about the ubuntu-users mailing list