bash "let" barfs on addition
matthew.flaschen at gatech.edu
Thu Mar 12 23:34:56 UTC 2009
> 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:
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/
support arbitrary precision.
More information about the ubuntu-users