changeset 31070:398a67a91798

maint: Merge stable to default
author Arun Giridhar <arungiridhar@gmail.com>
date Sat, 04 Jun 2022 17:14:05 -0400
parents 0b402f523f09 (current diff) 43974344fe19 (diff)
children 396f60e0b984
files
diffstat 1 files changed, 58 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/numbers.txi	Sat Jun 04 22:17:58 2022 +0200
+++ b/doc/interpreter/numbers.txi	Sat Jun 04 17:14:05 2022 -0400
@@ -775,6 +775,64 @@
 @noindent
 where the returned value is single precision.
 
+Many functions and operators will also promote integer or logical types to
+double, or single to double, especially if they take only one argument.
+
+@example
+@group
+a = det (int8 ([1 2; 3 4]))
+    @result{} a = -2
+class (a)
+    @result{} double
+@end group
+@end example
+
+But there are also exceptions for promoting to double, especially if the
+function or operator in question can take multiple arguments.
+
+@example
+@group
+a = eig (int8 ([1 2; 3 4]))
+    @result{} error: eig: wrong type argument 'int8 matrix'
+@end group
+@end example
+
+When the two operands are both integers but of different widths, then the
+behavior depends on the operator or the function in question.  For some
+operators and functions, narrow-bitwidth operands are promoted to a wider
+bitwidth:
+
+@example
+@group
+a = min (int8 (100), int16 (200))
+    @result{} 100
+class (a)
+    @result{} int16
+@end group
+@end example
+
+However, not all functions or operators will accept integer operands of
+differing types:
+
+@example
+@group
+int8 (100) + int16 (200)
+   @result{} error: binary operator '+' not implemented
+   for 'int8 scalar' by 'int16 scalar' operations
+@end group
+@end example
+
+Further, in most cases, both operands need to be signed or both need to be
+unsigned.  Mixing signed and unsigned usually causes an error, even if they
+are of the same bitwidth.
+
+@example
+@group
+min (int8 (100), uint16 (200))
+   @result{} error: min: cannot compute min (int8 scalar, uint16 scalar)
+@end group
+@end example
+
 In the case of mixed type indexed assignments, the type is not
 changed.  For example,