Angle.Trig (angle v1.0.1)

Wraps Erlang's :math module to provide versions of it's trigonomic functions which work with the Angle type.

Erlang's :math module relies on your libc implementation. Which return potentially different values for these functions based on the approximations they use. Specifally you may see small differences between values computed by macOS' libc and GNU libc. This can lead to surprising test failures; you most likely want to limit accuracy in tests to a few decimal places.

Link to this section Summary

Functions

Calculate the inverse trigonometric cosine (also known as arccosine) angle of a real value x between -1 and 1.

Calculate the inverse hyperbolic cosine angle of a real value x between 1 and +∞.

Calculate the inverse trigonometric sine (also known as arcsine) angle of a real value x between -1 and 1.

Calculate the inverse hyperbolic sine angle of a real value x.

Calculate the inverse trigonometric tangent (also known as arctangent) angle between the positive x-axis and the coordinates x, y.

Calculate the inverse trigonometric tangent (also known as arctangent) angle of any real value x.

Calculate the cosine (sine complement) of angle.

Calculate the hyperbolic cosine of angle.

Calculate the sine of angle.

Calculate the hyperbolic sine of angle.

Caculate the tangent of angle.

Calculate the hyperbolic tangent of angle.

Link to this section Functions

@spec acos(number()) :: {:ok, Angle.t()} | {:error, term()}

Calculate the inverse trigonometric cosine (also known as arccosine) angle of a real value x between -1 and 1.

Examples:

iex> Angle.Trig.acos(1)
...> |> inspect()
"{:ok, #Angle<0>}"

iex> Angle.Trig.acos(-1)
...> |> inspect()
"{:ok, #Angle<3.141592653589793㎭>}"
@spec acosh(number()) :: {:ok, Angle.t()} | {:error, term()}

Calculate the inverse hyperbolic cosine angle of a real value x between 1 and +∞.

Examples

iex> Angle.Trig.acosh(1)
...> |> inspect()
"{:ok, #Angle<0>}"

iex> Angle.Trig.acosh(2)
...> |> inspect()
"{:ok, #Angle<1.3169578969248166㎭>}"
@spec asin(number()) :: {:ok, Angle.t()} | {:error, term()}

Calculate the inverse trigonometric sine (also known as arcsine) angle of a real value x between -1 and 1.

Examples

iex> Angle.Trig.asin(0)
...> |> inspect()
"{:ok, #Angle<0>}"

iex> Angle.Trig.asin(1)
...> |> inspect()
"{:ok, #Angle<1.5707963267948966㎭>}"
@spec asinh(number()) :: {:ok, Angle.t()} | {:error, term()}

Calculate the inverse hyperbolic sine angle of a real value x.

Examples

iex> Angle.Trig.asinh(-1)
...> |> inspect()
"{:ok, #Angle<-0.881373587019543㎭>}"

iex> Angle.Trig.asinh(1)
...> |> inspect()
"{:ok, #Angle<0.881373587019543㎭>}"
@spec atan2(number(), number()) :: {:ok, Angle.t()} | {:error, term()}

Calculate the inverse trigonometric tangent (also known as arctangent) angle between the positive x-axis and the coordinates x, y.

Examples

iex> Angle.Trig.atan2(-1, -2)
...> |> inspect()
"{:ok, #Angle<-2.677945044588987㎭>}"

iex> Angle.Trig.atan2(1, 2)
...> |> inspect()
"{:ok, #Angle<0.4636476090008061㎭>}"
@spec atan(number()) :: {:ok, Angle.t()} | {:error, term()}

Calculate the inverse trigonometric tangent (also known as arctangent) angle of any real value x.

Examples

iex> Angle.Trig.atan(-1)
...> |> inspect()
"{:ok, #Angle<-0.7853981633974483㎭>}"

iex> Angle.Trig.atan(1)
...> |> inspect()
"{:ok, #Angle<0.7853981633974483㎭>}"
@spec cos(Angle.t()) :: {Angle.t(), float()}

Calculate the cosine (sine complement) of angle.

The cosine is the ratio of the length of the adjacent side to the length of the hypotenuse of a right angle triangle.

Returns a float between -1.0 and 1.0

Example

iex> ~a(180)d
...> |> cos()
...> |> inspect()
"{#Angle<180°>, -1.0}"
@spec cosh(Angle.t()) :: {Angle.t(), float()}

Calculate the hyperbolic cosine of angle.

Returns a float between 1.0 and +∞.

Example

iex> ~a(0)
...> |> cosh()
...> |> inspect()
"{#Angle<0>, 1.0}"
@spec sin(Angle.t()) :: {Angle.t(), float()}

Calculate the sine of angle.

The sine of an angle is the ratio of the length of the opposite side to the length of the hypotenuse of a right angle triangle.

Returns a float between -∞ and +∞.

Example

iex> ~a(90)d
...> |> sin()
...> |> inspect()
"{#Angle<90°>, 1.0}"
@spec sinh(Angle.t()) :: {Angle.t(), float()}

Calculate the hyperbolic sine of angle.

Returns a float between -∞ and +∞.

Example

iex> ~a(0)
...> |> sinh()
...> |> inspect()
"{#Angle<0>, 0.0}"
@spec tan(Angle.t()) :: {Angle.t(), float()}

Caculate the tangent of angle.

The tangent of an angle is the ratio of the length of the opposite side to the length of the adjacent side of a right angle triangle.

Returns a float between -∞ and +∞.

Example

iex> ~a(0)
...> |> tan()
...> |> inspect()
"{#Angle<0>, 0.0}"
@spec tanh(Angle.t()) :: {Angle.t(), float()}

Calculate the hyperbolic tangent of angle.

Returns a float between -1.0 and 1.0

Example

iex> ~a(0)
...> |> tanh()
...> |> inspect()
"{#Angle<0>, 0.0}"