Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update promotion rules #468

Merged
merged 3 commits into from
Jan 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/reference-manual/expressions.Rmd
Original file line number Diff line number Diff line change
@@ -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 from integer to real; 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 all
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.

@@ -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 [,] real` or `array [,] complex` is required.

#### Literals {-}

5 changes: 3 additions & 2 deletions src/reference-manual/syntax.Rmd
Original file line number Diff line number Diff line change
@@ -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 {-}