Package: coreutils
Version: 8.13-3.2
Severity: normal

quote from expr(1) info file:

    When built with support for the GNU MP library, `expr' uses
    arbitrary-precision arithmetic; otherwise, it uses native arithmetic
    types and may fail due to arithmetic overflow.

This appears to actually happen:

    $ expr 1000000 \* 1000000 \* 1000000
    1000000000000000000
    $ 
    $ expr 1000000 \* 1000000 \* 1000000 \* 5
    5000000000000000000
    $ 
    $ expr 1000000 \* 1000000 \* 1000000 \* 9
    9000000000000000000
    $ 
    $ expr 1000000 \* 1000000 \* 1000000 \* 10
    expr: *: Numerical result out of range

Note that 10^19 is close to 2^64 :

    $ bc <<< '10^19 ; 2^64'
    10000000000000000000
    18446744073709551616

Any shell in current use offers basic arithmetic facilities; surely the
only remaining potential benefit of "expr" is extended-range arithmetic. 
Why then is it not compiled to do that?

Alternatively, it appears that gcc supports native 128-bit integers, at
least on some targets, including AMD64. Perhaps use could be made of
that feature.

http://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html

See here for a related bug:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=608832

Package libgmp10, the above mentioned "GNU MP library", has an
Installed-Size of 492 (kilobytes?).

Package bc, an arbitrary-precision calculator, which appears to be
statically linked against its own MP arithmetic library, has an
Installed-Size of 260.

Surely coreutils can be dynamically linked against some stripped-down
library which will solve this problem? It doesn't seem like implementing
variable precision arithmetic ("+", "-", "*", "/", "%") and relational
("==", "!=", "<", "<=", ">", ">=") operators should take more than a few
tens of kilobytes, maximum.

The version of "expr" in the busybox package suffers from the same
problem. Should a separate bug be filed for that?


-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'stable-updates'), (500, 'unstable'), 
(500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.2.0-3-amd64 (SMP w/1 CPU core)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/dash

Versions of packages coreutils depends on:
ii  dpkg          1.16.4.3
ii  install-info  4.13a.dfsg.1-6
ii  libacl1       2.2.51-8
ii  libattr1      1:2.4.46-8
ii  libc6         2.13-33
ii  libselinux1   2.0.96-1

coreutils recommends no packages.

coreutils suggests no packages.

-- no debconf information


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to