From owner-freebsd-hackers@FreeBSD.ORG Sun Apr 6 15:07:31 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 760D337B401 for ; Sun, 6 Apr 2003 15:07:31 -0700 (PDT) Received: from mta6.snfc21.pbi.net (mta6.snfc21.pbi.net [206.13.28.240]) by mx1.FreeBSD.org (Postfix) with ESMTP id 11B1743F93 for ; Sun, 6 Apr 2003 15:07:31 -0700 (PDT) (envelope-from mbsd@pacbell.net) Received: from atlas ([64.160.45.145]) by mta6.snfc21.pbi.net (iPlanet Messaging Server 5.1 HotFix 1.6 (built Oct 18 2002)) with ESMTP id <0HCY00MOU04IX1@mta6.snfc21.pbi.net> for freebsd-hackers@freebsd.org; Sun, 06 Apr 2003 15:07:30 -0700 (PDT) Date: Sun, 06 Apr 2003 15:07:30 -0700 (PDT) From: =?ISO-8859-1?Q?Mikko_Ty=F6l=E4j=E4rvi?= In-reply-to: <20030406213453.GB4780@wjv.com> X-X-Sender: mikko@atlas.home To: freebsd-hackers@freebsd.org Message-id: <20030406145748.O1122@atlas.home> MIME-version: 1.0 Content-type: TEXT/PLAIN; charset=US-ASCII Content-transfer-encoding: 7BIT References: <20030406190054.AA08537B404@hub.freebsd.org> <20030406213453.GB4780@wjv.com> Subject: Re: /bin/sh and BIG NUMBERS X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Apr 2003 22:07:31 -0000 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 > > Subject: Re: /bin/sh and BIG NUMBERS > > To: Alex Semenyaka > > 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 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