Skip to content

Commit

Permalink
Improve definition of exponentiation.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansOlsson committed Nov 21, 2022
1 parent 206a804 commit 88e40a9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions chapters/arrays.tex
Expand Up @@ -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!.
Expand Down

0 comments on commit 88e40a9

Please sign in to comment.