diff options
author | James Youngman <jay@gnu.org> | 2008-08-02 21:49:46 +0100 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2008-08-06 08:47:55 +0200 |
commit | f65cafd67b33009d23f940968bbe7f9a08d6fe13 (patch) | |
tree | 46b81ec96bceed2c2b7b6dffa3aa4e8646db952e /doc/coreutils.texi | |
parent | d9207b48a3e0763a7a93eb17c26ae5704b798d76 (diff) | |
download | coreutils-f65cafd67b33009d23f940968bbe7f9a08d6fe13.tar.xz |
expr: support arbitrary-precision arithmetic
* src/Makefile.am (expr_LDADD): Link expr against GNU MP.
* doc/coreutils.texi (expr invocation): Describe --bignum,
--no-bignum. Explain the new arbitrary-precision functionality.
* NEWS: Indicate that arbitrary-precision arithmetic is now
supported in expr.
* src/expr.c (enum valtype): Added mp_integer, signifying a GNU MP
number.
(usage): Document the new options --bignum and --no-bignum which
force and prohibit the use of arbitrary-precision arithmetic,
respectively.
(long_options): data structure for getopt_long, which we need to
use to parse the options mentioned above.
(main): parse these options with getopt_long instead of
parse_long_options.
(valinfo): Downgrade the numeric member of the union from
intmax_t to signed long, since MP lacks functions for promoting an
intmax_t to an arbitrary-precision quantity.
(enum arithmetic_mode): Represents the current choice between
--bignum, --no-bignum and the default (automatically switch from
one to the other if needed).
(integer_overflow): issue a more explicit error message indicating
that MP is not available.
(string_too_long): new function, emits a fatal error message for
the case where an argument to the 'index' expression is too long
for a string offset to be represented.
(int_value): With --bignum, create the value as mp_integer rather
than plain integer.
(substr_value): factored out of eval6; implements "substr".
(freev): also destroy mp_integer values. Check that no mp_integer
values exist if --no-bignum was specified.
(printv, null, tostring): support mp_integer.
(toint): new funtion for converting from string or mp_integer to
integer.
(getsize): extracts a size_t value from a VALUE object; used to
implement substr.
(promote): promotes a value from integer to mp_integer.
(domult, dodivide): functions for multiplication and division,
factored out of eval4.
(doadd): addition/subraction function, factpred out of eval3.
(eval3): support mp_integer types; call doadd.
(eval4): support mp_integer types; call domult, dodivide.
(eval6): support mp_integer offsets and lengths for "substr" and
"index".
* TODO: Mention that expr supports arbitrary-precision arithmetic,
and suggest that this might also be a good idea for seq.
* AUTHORS (expr): Add James Youngman.
Diffstat (limited to 'doc/coreutils.texi')
-rw-r--r-- | doc/coreutils.texi | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/doc/coreutils.texi b/doc/coreutils.texi index fd1e79e09..f5a2e41a1 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -11066,8 +11066,21 @@ may be used for grouping in the usual manner. You must quote parentheses and many operators to avoid the shell evaluating them, however. -The only options are @option{--help} and @option{--version}. @xref{Common -options}. Options must precede operands. +By default, @command{expr} performs operations using native arithmetic +types, but if a numeric overflow occurs and @command{expr} was built +with support for the GNU MP library, @command{expr}, it will switch to +using arbitrary-precision arithmetic. + +Apart from @option{--help} and @option{--version} (@pxref{Common +options}), the following options are supported: + +@table @samp +@item --bignum +Forces the use of the GNU MP library. +@item --no-bignum +Forces the use of native operations only. In the event of a numeric +overflow, @command{expr} will fail, even if GNU MP is available. +@end table @cindex exit status of @command{expr} Exit status: |