3.6 Real-valued arithmetic operators

The arithmetic operators are presented using C++ notation. For instance operator+(x,y) refers to the binary addition operator and operator-(x) to the unary negation operator. In Stan programs, these are written using the usual infix and prefix notations as x + y and -x, respectively.

3.6.1 Binary infix operators

real operator+(real x, real y)
Return the sum of x and y. $\begin{equation*} (x + y) = \text{operator+}(x,y) = x+y \end{equation*}$
Available since 2.0

real operator-(real x, real y)
Return the difference between x and y. $\begin{equation*} (x - y) = \text{operator-}(x,y) = x - y \end{equation*}$
Available since 2.0

real operator*(real x, real y)
Return the product of x and y. $\begin{equation*} (x * y) = \text{operator*}(x,y) = xy \end{equation*}$
Available since 2.0

real operator/(real x, real y)
Return the quotient of x and y. $\begin{equation*} (x / y) = \text{operator/}(x,y) = \frac{x}{y} \end{equation*}$
Available since 2.0

real operator^(real x, real y)
Return x raised to the power of y. $\begin{equation*} (x^\mathrm{\wedge}y) = \text{operator}^\mathrm{\wedge}(x,y) = x^y \end{equation*}$
Available since 2.5

3.6.2 Unary prefix operators

real operator-(real x)
Return the negation of the subtrahend x. $\begin{equation*} \text{operator-}(x) = (-x) \end{equation*}$
Available since 2.0

T operator-(T x)
Vectorized version of operator-. If T x is a (possibly nested) array of reals, -x is the same shape array where each individual number is negated.
Available since 2.31

real operator+(real x)
Return the value of x. $\begin{equation*} \text{operator+}(x) = x \end{equation*}$
Available since 2.0