changeset 31669:d949b698d1a9

maint: merge stable to default
author Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
date Fri, 16 Dec 2022 15:40:24 -0500
parents 6a66c157fa53 (current diff) 7d36562e5571 (diff)
children 67770ec6f0b5
files
diffstat 1 files changed, 32 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/expr.txi	Thu Dec 15 13:06:57 2022 -0800
+++ b/doc/interpreter/expr.txi	Fri Dec 16 15:40:24 2022 -0500
@@ -1081,32 +1081,38 @@
 @table @code
 @item @var{boolean1} && @var{boolean2}
 @opindex &&
-The expression @var{boolean1} is evaluated and converted to a scalar
-using the equivalent of the operation @code{all (@var{boolean1}(:))}.
-If it is false, the result of the overall expression is 0.  If it is
-true, the expression @var{boolean2} is evaluated and converted to a
-scalar using the equivalent of the operation @code{all
-(@var{boolean2}(:))}.  If it is true, the result of the overall expression
-is 1.  Otherwise, the result of the overall expression is 0.
+The expression @var{boolean1} is evaluated and converted to a scalar using
+the equivalent of the operation @code{all (@var{boolean1}(:))}.  If
+@var{boolean1} is not a logical value, it is considered true if its value
+is nonzero, and false if its value is zero.  If @var{boolean1} is an array,
+it is considered true only if it is non-empty and all elements are
+non-zero.  If @var{boolean1} evaluates to false, the result of the overall
+expression is false.  If it is true, the expression @var{boolean2} is
+evaluated in the same way as @var{boolean1}. If it is true, the result of
+the overall expression is true.  Otherwise the result of the overall
+expression is false.
 
-@strong{Warning:} there is one exception to the rule of evaluating
-@code{all (@var{boolean1}(:))}, which is when @code{boolean1} is the
-empty matrix.  The truth value of an empty matrix is always @code{false}
-so @code{[] && true} evaluates to @code{false} even though
+@strong{Warning:} the one exception to the equivalence with evaluating
+@code{all (@var{boolean1}(:))} is when @code{boolean1} an the empty array.
+For @sc{MATLAB} compatibility, the truth value of an empty array is always
+@code{false} so @code{[] && true} evaluates to @code{false} even though
 @code{all ([])} is @code{true}.
 
 @item @var{boolean1} || @var{boolean2}
 @opindex ||
-The expression @var{boolean1} is evaluated and converted to a scalar
-using the equivalent of the operation @code{all (@var{boolean1}(:))}.
-If it is true, the result of the overall expression is 1.  If it is
-false, the expression @var{boolean2} is evaluated and converted to a
-scalar using the equivalent of the operation @code{all
-(@var{boolean2}(:))}.  If it is true, the result of the overall expression
-is 1.  Otherwise, the result of the overall expression is 0.
+The expression @var{boolean1} is evaluated and converted to a scalar using
+the equivalent of the operation @code{all (@var{boolean1}(:))}. If
+@var{boolean1} is not a logical value, it is considered true if its value
+is nonzero, and false if its value is zero.  If @var{boolean1} is an array,
+it is considered true only if it is non-empty and all elements are
+non-zero.  If @var{boolean1} evaluates to true, the result of the overall
+expression is true.  If it is false, the expression @var{boolean2} is
+evaluated in the same way as @var{boolean1}. If it is true, the result of
+the overall expression is true.  Otherwise the result of the overall
+expression is false.
 
-@strong{Warning:} the truth value of an empty matrix is always @code{false},
-see the previous list item for details.
+@strong{Warning:} the truth value of an empty matrix is always
+@code{false}, see the previous list item for details.
 @end table
 
 The fact that both operands may not be evaluated before determining the
@@ -1163,11 +1169,12 @@
 operands for the operator @samp{&}.
 
 @sc{matlab} has special behavior that allows the operators @samp{&} and
-@samp{|} to short-circuit when used in the truth expression for @code{if} and
-@code{while} statements.  Octave behaves the same way for compatibility,
-however, the use of the @samp{&} and @samp{|} operators in this way is
-strongly discouraged and a warning will be issued.  Instead, you should use
-the @samp{&&} and @samp{||} operators that always have short-circuit behavior.
+@samp{|} to short-circuit when used in the truth expression for @code{if}
+and @code{while} statements.  Octave behaves the same way for
+compatibility, however, the use of the @samp{&} and @samp{|} operators in
+this way is strongly discouraged and a warning will be issued.  Instead,
+you should use the @samp{&&} and @samp{||} operators that always have
+short-circuit behavior.
 
 Finally, the ternary operator (?:) is not supported in Octave.  If
 short-circuiting is not important, it can be replaced by the @code{ifelse}