Re: Recomended tutoial(s) on doing arithmetic in Bash scripts
On Sun, Mar 05, 2017 at 05:25:49PM +0100, tomas@tuxteam.de wrote:
> If you need floating point numbers, bc (or dc) are your next stops.
Or awk. For some problems, awk is fantastic.
On Sun, Mar 05, 2017 at 06:14:00PM +0000, GiaThnYgeia wrote:
> I see your 2 and raise you
> nosuchagency@bottomofthesea:~$ echo $(((3000000000+4000000000)/3))
> 2333333333
>
> Infinitely inaccurate digital systems
Bash uses 64-bit integers, since version 2.05b. If you want arbitrary
precision, use bc (or a programming language with an arbitrary precision
math library).
POSIX shells in general may use smaller integers than that. I wouldn't
expect anything outside the range (-2^31 .. +2^31) to be portable.
expr(1) is legacy rubbish and should never be used in new scripts.
Reply to: