Subject: Re: 64 bit shell arithmetic
To: Markus Mayer <firstname.lastname@example.org>
From: David Laight <email@example.com>
Date: 03/24/2007 08:02:44
On Fri, Mar 23, 2007 at 05:17:37PM -0700, Markus Mayer wrote:
> It looks like I discovered a problem with shell arithmetic with large
> number (numbers larger than "signed long").
> Here is an example (determine the amount of RAM and convert it into
> # total_ram=`/sbin/sysctl hw.usermem64 | sed -e 's/.* = //'`
> # echo $total_ram
> # ram_mb=$(($total_ram/1048576))
> # echo $ram_mb
> -192 MB is obviously wrong.
The shell arithemtic is done with 32bit signed integers.
So just isn't going to work with arbitrarily large values.
It does look as thought the shell is using 'signed int', whereas the
posix spec (at least the TOG pages) say 'signed long' (at least).
That change can be made - and only affects 64bit ports.
David Laight: firstname.lastname@example.org