diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 03323f8c1..07c4eb351 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -1268,10 +1268,19 @@ \subsection{Element-wise Division}\label{array-element-wise-division}\label{elem \subsection{Element-wise Exponentiation}\label{element-wise-exponentiation} -Exponentiation \lstinline!a ^ b! is defined as \lstinline[language=C]!pow(double a, double b)! in the ANSI~C library if both \lstinline!a! and \lstinline!b! are -\lstinline!Real! scalars. A \lstinline!Real! scalar value is returned. If \lstinline!a! or \lstinline!b! are \lstinline!Integer! scalars, they are -automatically promoted to \lstinline!Real!. Consequences of exceptional situations, such as ($\text{\lstinline!a!} = 0.0$ and $\text{\lstinline!b!} \leq 0.0$, -$\text{\lstinline!a!} < 0$ and \lstinline!b! is not an integer) or overflow are undefined. +Exponentiation \lstinline!a ^ b! always return a \lstinline!Real! scalar value, and it is required that \lstinline!a! and \lstinline!b! are scalar \lstinline!Real! or \lstinline!Integer! values. +The result should correspond to mathematical exponentiation (ideally the correctly rounded result based on the inputs) with the following special cases: +\begin{itemize} +\item If $\text{\lstinline!a!} = 0.0$ and $\text{\lstinline!b!} = 0$ for an \lstinline!Integer! expression \lstinline!b! the result is $0.0$. +\item If $\text{\lstinline!a!} < 0$ and \lstinline!b! is an \lstinline!Integer! or a \lstinline!Real! having an integer value, the result is defined as $\pm |a|^b$, with sign depending on whether \lstinline!b! is even (positive) or odd (negative). +\item Consequences of other exceptional situations, such as ($\text{\lstinline!a!} = 0.0$ and $\text{\lstinline!b!} = 0.0$ for a \lstinline!Real b!, +$\text{\lstinline!a!} = 0.0$ and $\text{\lstinline!b!} < 0$, or $\text{\lstinline!a!} < 0$ and \lstinline!b! does not have an integer value) or overflow are undefined. +\end{itemize} +Except for defining the special case of $0.0^0$ it corresponds to \lstinline[language=C]!pow(double a, double b)! in the ANSI~C library. +\begin{nonnormative} +The result is always \lstinline!Real! due to the potential for integer overflow and negative exponents. +Treating an \lstinline!Integer! exponent special imply that we can freely use $x^n$ in a power-series. +\end{nonnormative} Element-wise exponentiation \lstinline!a .^ b! of numeric scalars, vectors, matrices, or arrays \lstinline!a! and \lstinline!b! requires a numeric type class for \lstinline!a! and \lstinline!b! and either \lstinline!size(a) = size(b)! or scalar \lstinline!a! or scalar \lstinline!b!.