Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Apr 2003 11:53:09 +0300
From:      Peter Pentchev <roam@ringlet.net>
To:        Giorgos Keramidas <keramida@ceid.upatras.gr>
Cc:        Alex Semenyaka <alexs@ratmir.ru>
Subject:   Re: /bin/sh and BIG NUMBERS
Message-ID:  <20030407085309.GC527@straylight.oblivion.bg>
In-Reply-To: <20030406032450.GC4130@gothmog.gr>
References:  <20030405030629.GA2669@snark.ratmir.ru> <20030406032450.GC4130@gothmog.gr>

next in thread | previous in thread | raw e-mail | index | archive | help

--4SFOXa2GPu3tIq4H
Content-Type: text/plain; charset=windows-1251
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Apr 06, 2003 at 06:24:50AM +0300, Giorgos Keramidas wrote:
> 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
> >
> > That was not a problem 5 years ago... But now we have a lot of 64-bits
> > values.  So those old scripts which perfectly worked for a long time
> > now can give wrong results, and you will not be able even to notice
> > it, there is no any diagnostics or such. The simplest way to fix it is
> > to switch internal /bin/sh arithmetics from 32 to 64-bits (you know,
> > approach "640K ought to be enough for anybody").  I've did the patch
> > for this (below), please, look at it. Any comments or suggestions?
> >
> > diff -u -U1 -r ../sh.old/arith.h ./arith.h
> > --- ../sh.old/arith.h	Fri Jul 19 08:38:51 2002
> > +++ ./arith.h	Sat Apr  5 06:26:48 2003
> > @@ -36,3 +36,3 @@
> >
> > -int arith(char *);
> > +long long arith(char *);
> >  int expcmd(int , char **);
> >
> > [snip rest of long-long using patch]
>=20
> Nice idea, but we should probably ask the -standards people if we
> can/should make this use uint64_t and %jd instead of `long long'
> (using %qd is deprecated and %lld is advised in printf(3) anyway).

intmax_t might be a better choice, if %jd is used :)

G'luck,
Peter

--=20
Peter Pentchev	roam@ringlet.net    roam@sbnd.net    roam@FreeBSD.org
PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
If I had finished this sentence,

--4SFOXa2GPu3tIq4H
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+kTx07Ri2jRYZRVMRAqZyAJ4tn1b9FvmYxoSdLltW+JDuJpHwawCfXrz8
Ue/A/ZctKUKp6spN4N4ejAA=
=RNyF
-----END PGP SIGNATURE-----

--4SFOXa2GPu3tIq4H--



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