Skip to content

Commit b88ea73

Browse files
authored
Merge pull request #468 from stan-dev/promotion-docs
Update promotion rules
2 parents 39fc142 + 92a416a commit b88ea73

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/reference-manual/expressions.Rmd

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,10 @@ a ? b : c
613613
```
614614

615615
is an expression of the promoted type of `b` and `c`. The
616-
only promotion allowed in Stan is from integer to real; if one
616+
only promotion allowed in Stan is integer -> real -> complex; e.g. if one
617617
argument is of type `int` and the other of type `real`, the
618-
conditional expression as a whole is of type `real`. In all
619-
other cases, the arguments have to be of the same underlying Stan type
618+
conditional expression as a whole is of type `real`.
619+
In other cases, the arguments have to be of the same underlying Stan type
620620
(i.e., constraints don't count, only the shape) and the conditional
621621
expression is of that type.
622622

@@ -1070,7 +1070,7 @@ to complex expressions.
10701070

10711071
### Promotion
10721072

1073-
There are two promotion rules. First, integer expressions of type
1073+
There are three promotion rules. First, integer expressions of type
10741074
`int` may be used anywhere an expression of type `real` is used. An
10751075
integer is promoted to real by casting it in the underlying C++.
10761076

@@ -1083,7 +1083,9 @@ Promotion is transitive, so that integers may be promoted to complex
10831083
numbers in two stages, first converting the integer to real, then
10841084
converting the real value to a complex type.
10851085

1086-
1086+
The third rule is (starting with Stan 2.29), array types are promoted
1087+
according to their contained type. For example, `array[,] int` may be
1088+
used where `array [,] real` or `array [,] complex` is required.
10871089

10881090
#### Literals {-}
10891091

src/reference-manual/syntax.Rmd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,9 @@ quantities blocks.
375375

376376
The types of expressions used for elements in array expressions
377377
(`'{' expressions '}'`) must all be of the same type or a mixture
378-
of `int` and `real` types (in which case the result is
379-
promoted to be of type `real`).
378+
of scalar (`int`, `real` and `complex`) types (in which case the result
379+
is promoted to be of the highest type on the `int -> real -> complex`
380+
hierarchy).
380381

381382

382383
### Forms of numbers {-}

0 commit comments

Comments
 (0)