Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 06 Apr 2003 15:07:30 -0700 (PDT)
From:      =?ISO-8859-1?Q?Mikko_Ty=F6l=E4j=E4rvi?= <mbsd@pacbell.net>
To:        freebsd-hackers@freebsd.org
Subject:   Re: /bin/sh and BIG NUMBERS
Message-ID:  <20030406145748.O1122@atlas.home>
In-Reply-To: <20030406213453.GB4780@wjv.com>
References:  <20030406190054.AA08537B404@hub.freebsd.org> <20030406213453.GB4780@wjv.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 6 Apr 2003, Bill Vermillion wrote:

> On Sun, Apr 06, 2003 at 12:00 ,
> freebsd-hackers-request@freebsd.org exclaimed "Las Cucarachas
> entran, Pero no puede en salir", and then rambled on saying with:
>
> >    2. Re: /bin/sh and BIG NUMBERS (Giorgos Keramidas)
>
>
> > Message: 2
> > Date: Sun, 6 Apr 2003 06:24:50 +0300
> > From: Giorgos Keramidas <keramida@ceid.upatras.gr>
> > Subject: Re: /bin/sh and BIG NUMBERS
> > To: Alex Semenyaka <alexs@ratmir.ru>
> > Cc: freebsd-hackers@freebsd.org
> > Message-ID: <20030406032450.GC4130@gothmog.gr>
> > Content-Type: text/plain; charset=us-ascii
>
> > On 2003-04-05 07:06, Alex Semenyaka <alexs@ratmir.ru> wrote:
> > > I found that /bin/sh cannot handle numbers those do not fit to integer
> > > type.  That is not too bad. Too bad that it just silently warps them
> > > in arithmetical operations:
>
> > > alexs@snark> /bin/sh -c 'echo $((10000000000-1))'
> > > 2147483646
>
> Not all shells have that problem.  I'm using the real KSH from AT&T
> via the ports.  It's returns 999999999 quite nicely :-)

Ksh seems to use floats for calculations, and so instead silently
drops precision when dealing with sufficiently large numbers:

 atlas% ksh93 -c 'echo $((10000000000002-1))'
 1e+13

Zsh uses 64 bit ints, which silently overflow, albeit at larger values
than FreeBSD's sh(1).  The same goes for bash.

Looks like shells aren't the best environment for bignum arithmetic :^)

     $.02,
     /Mikko



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030406145748.O1122>