Trigonometric functions

Table of contents


Trigonometric functions

template<typename T>
constexpr return_t<T> cos(const T x) noexcept

Compile-time cosine function.

Parameters

x – a real-valued input.

Returns

the cosine function using

\[ \cos(x) = \frac{1-\tan^2(x/2)}{1+\tan^2(x/2)} \]

template<typename T>
constexpr return_t<T> sin(const T x) noexcept

Compile-time sine function.

Parameters

x – a real-valued input.

Returns

the sine function using

\[ \sin(x) = \frac{2\tan(x/2)}{1+\tan^2(x/2)} \]

template<typename T>
constexpr return_t<T> tan(const T x) noexcept

Compile-time tangent function.

Parameters

x – a real-valued input.

Returns

the tangent function using

\[ \tan(x) = \dfrac{x}{1 - \dfrac{x^2}{3 - \dfrac{x^2}{5 - \ddots}}} \]
To deal with a singularity at \( \pi / 2 \), the following expansion is employed:
\[ \tan(x) = - \frac{1}{x-\pi/2} - \sum_{k=1}^\infty \frac{(-1)^k 2^{2k} B_{2k}}{(2k)!} (x - \pi/2)^{2k - 1} \]
where \( B_n \) is the n-th Bernoulli number.


Inverse trigonometric functions

template<typename T>
constexpr return_t<T> acos(const T x) noexcept

Compile-time arccosine function.

Parameters

x – a real-valued input, where \( x \in [-1,1] \).

Returns

the inverse cosine function using

\[ \text{acos}(x) = \text{atan} \left( \frac{\sqrt{1-x^2}}{x} \right) \]

template<typename T>
constexpr return_t<T> asin(const T x) noexcept

Compile-time arcsine function.

Parameters

x – a real-valued input, where \( x \in [-1,1] \).

Returns

the inverse sine function using

\[ \text{asin}(x) = \text{atan} \left( \frac{x}{\sqrt{1-x^2}} \right) \]

template<typename T>
constexpr return_t<T> atan(const T x) noexcept

Compile-time arctangent function.

Parameters

x – a real-valued input.

Returns

the inverse tangent function using

\[ \text{atan}(x) = \dfrac{x}{1 + \dfrac{x^2}{3 + \dfrac{4x^2}{5 + \dfrac{9x^2}{7 + \ddots}}}} \]

template<typename T1, typename T2>
constexpr common_return_t<T1, T2> atan2(const T1 y, const T2 x) noexcept

Compile-time two-argument arctangent function.

Parameters
  • y – a real-valued input.

  • x – a real-valued input.

Returns

\[ \text{atan2}(y,x) = \begin{cases} \text{atan}(y/x) & \text{ if } x > 0 \\ \text{atan}(y/x) + \pi & \text{ if } x < 0 \text{ and } y \geq 0 \\ \text{atan}(y/x) - \pi & \text{ if } x < 0 \text{ and } y < 0 \\ + \pi/2 & \text{ if } x = 0 \text{ and } y > 0 \\ - \pi/2 & \text{ if } x = 0 \text{ and } y < 0 \end{cases} \]
The function is undefined at the origin, however the following conventions are used.
\[ \text{atan2}(y,x) = \begin{cases} +0 & \text{ if } x = +0 \text{ and } y = +0 \\ -0 & \text{ if } x = +0 \text{ and } y = -0 \\ +\pi & \text{ if } x = -0 \text{ and } y = +0 \\ - \pi & \text{ if } x = -0 \text{ and } y = -0 \end{cases} \]