summaryrefslogtreecommitdiffstats
path: root/bin/expr/expr.1
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>2002-05-10 22:59:29 +0000
committerwollman <wollman@FreeBSD.org>2002-05-10 22:59:29 +0000
commite11cb46ee8e7eea44531903aaac525bbd80f14c0 (patch)
treeeb552a2a3e43e767f64fbdca6a0411905d9c9852 /bin/expr/expr.1
parent6cd7fcea88d41d92ee11ffbf6d144c3ea9696084 (diff)
downloadFreeBSD-src-e11cb46ee8e7eea44531903aaac525bbd80f14c0.zip
FreeBSD-src-e11cb46ee8e7eea44531903aaac525bbd80f14c0.tar.gz
The response to my POSIX interpretation request says that `expr'
is required to be oblivious to overflow and to use the data type `long'. (Division by zero is undefined in ISO C so it's still OK to check for it here.) Add a new `-e' flag to get the old, more useful behavior.
Diffstat (limited to 'bin/expr/expr.1')
-rw-r--r--bin/expr/expr.139
1 files changed, 23 insertions, 16 deletions
diff --git a/bin/expr/expr.1 b/bin/expr/expr.1
index 4669000..1425e00 100644
--- a/bin/expr/expr.1
+++ b/bin/expr/expr.1
@@ -30,7 +30,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 22, 2002
+.Dd May 10, 2002
.Dt EXPR 1
.Os
.Sh NAME
@@ -38,7 +38,7 @@
.Nd evaluate expression
.Sh SYNOPSIS
.Nm
-.Op Fl \&-
+.Op Fl e
.Ar expression
.Sh DESCRIPTION
The
@@ -50,15 +50,25 @@ and writes the result on standard output.
All operators and operands must be passed as separate arguments.
Several of the operators have special meaning to command interpreters
and must therefore be quoted appropriately.
+All integer operands are interpreted in base 10.
.Pp
-Arithmetic operations are performed using signed integer math,
-in the largest integral type available in the C language. The
+Arithmetic operations are performed using signed integer math.
+If the
+.Fl e
+flag is specified, arithmetic uses the C
+.Ql intmax_t
+data type (the largest integral type available), and
.Nm
-utility will detect arithmetic overflow and division by zero, and
-returns with an exit status of 2 in those cases. If a numeric operand
-is specified which is so large as to overflow conversion to an integer,
-it is parsed as a string instead. All numeric operands are interpreted
-in base 10.
+will detect arithmetic overflow and return an error indication.
+If a numeric operand is specified which is so large as to overflow
+conversion to an integer, it is parsed as a string instead.
+If
+.Fl e
+is not specified, arithmetic operations and parsing of integer
+arguments will overflow silently according to the rules of the C
+standard, and integer computations will be performed using the
+.Ql long
+data type.
.Pp
Operators are listed below in order of increasing precedence; all
are left-associative.
@@ -174,7 +184,7 @@ command, one might rearrange the expression:
More generally, parenthesize possibly-negative values:
.Dl a=$(expr \e( $a \e) + 1)
.It
-The following example prints the filename portion of a pathname stored
+This example prints the filename portion of a pathname stored
in variable
.Va a .
Since
@@ -231,9 +241,6 @@ utility conforms to
provided that the
.Ev EXPR_COMPAT
environment variable is not defined.
-.Tn POSIX
-does not specify whether arithmetic overflow is detected, nor does it specify
-the possible range of integer arguments to
-.Nm ,
-so a portable application must assume that the range is small and that
-overflow may not be detected.
+The
+.Fl e
+flag is an extension.
OpenPOWER on IntegriCloud