From 3ad26a76302b355eeeae51df331661dc60f89e0f Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Wed, 12 Jan 2022 10:01:51 -0500 Subject: [PATCH 1/3] Update promotion rules --- src/reference-manual/expressions.Rmd | 10 ++++++---- src/reference-manual/syntax.Rmd | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/reference-manual/expressions.Rmd b/src/reference-manual/expressions.Rmd index 691d37704..a5373a943 100644 --- a/src/reference-manual/expressions.Rmd +++ b/src/reference-manual/expressions.Rmd @@ -613,9 +613,9 @@ a ? b : c ``` is an expression of the promoted type of `b` and `c`. The -only promotion allowed in Stan is from integer to real; if one +only promotion allowed in Stan is integer -> real -> complex; if one argument is of type `int` and the other of type `real`, the -conditional expression as a whole is of type `real`. In all +conditional expression as a whole is of type `real`. In other cases, the arguments have to be of the same underlying Stan type (i.e., constraints don't count, only the shape) and the conditional expression is of that type. @@ -1070,7 +1070,7 @@ to complex expressions. ### Promotion -There are two promotion rules. First, integer expressions of type +There are three promotion rules. First, integer expressions of type `int` may be used anywhere an expression of type `real` is used. An integer is promoted to real by casting it in the underlying C++. @@ -1083,7 +1083,9 @@ Promotion is transitive, so that integers may be promoted to complex numbers in two stages, first converting the integer to real, then converting the real value to a complex type. - +The third rule is (starting with Stan 2.29), array types are promoted +according to their contained type. For example, `array[,] int` may be +used where `array [,] complex` is required. #### Literals {-} diff --git a/src/reference-manual/syntax.Rmd b/src/reference-manual/syntax.Rmd index 9517b1d25..eecaf43aa 100644 --- a/src/reference-manual/syntax.Rmd +++ b/src/reference-manual/syntax.Rmd @@ -375,8 +375,9 @@ quantities blocks. The types of expressions used for elements in array expressions (`'{' expressions '}'`) must all be of the same type or a mixture -of `int` and `real` types (in which case the result is -promoted to be of type `real`). +of scalar (`int`, `real` and `complex`) types (in which case the result +is promoted to be of the highest type on the `int -> real -> complex` +hierarchy). ### Forms of numbers {-} From fbb1af59d8e49562de2e23ded1ee8ab61469b208 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Wed, 12 Jan 2022 10:13:23 -0500 Subject: [PATCH 2/3] Reword --- src/reference-manual/expressions.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/reference-manual/expressions.Rmd b/src/reference-manual/expressions.Rmd index a5373a943..ca95933fc 100644 --- a/src/reference-manual/expressions.Rmd +++ b/src/reference-manual/expressions.Rmd @@ -613,10 +613,10 @@ a ? b : c ``` is an expression of the promoted type of `b` and `c`. The -only promotion allowed in Stan is integer -> real -> complex; if one +only promotion allowed in Stan is integer -> real -> complex; e.g. if one argument is of type `int` and the other of type `real`, the -conditional expression as a whole is of type `real`. In -other cases, the arguments have to be of the same underlying Stan type +conditional expression as a whole is of type `real`. +In other cases, the arguments have to be of the same underlying Stan type (i.e., constraints don't count, only the shape) and the conditional expression is of that type. From 92a416a4a1f6a71c0ab4f30f6f8ae20c933598ce Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Wed, 12 Jan 2022 10:56:45 -0500 Subject: [PATCH 3/3] Update src/reference-manual/expressions.Rmd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rok Češnovar --- src/reference-manual/expressions.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reference-manual/expressions.Rmd b/src/reference-manual/expressions.Rmd index ca95933fc..501c263d5 100644 --- a/src/reference-manual/expressions.Rmd +++ b/src/reference-manual/expressions.Rmd @@ -1085,7 +1085,7 @@ converting the real value to a complex type. The third rule is (starting with Stan 2.29), array types are promoted according to their contained type. For example, `array[,] int` may be -used where `array [,] complex` is required. +used where `array [,] real` or `array [,] complex` is required. #### Literals {-}