Trigonometry v0.1.0
DegToRad
pub func DegToRad(x: float64) -> float64
pub func DegToRad(x: float32) -> float32
Converts an angle from degrees to radians.
The conversion scales by the nearest float64 to Pi / 180, making DegToRad(180.0) exactly Pi. A signed zero
keeps its sign, infinities keep their sign, and a NaN remains a NaN.
| Overload | Summary |
|---|---|
pub func DegToRad(x: float64) -> float64 | Converts an angle from degrees to radians. |
pub func DegToRad(x: float32) -> float32 | Converts an angle from degrees to radians at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | angle in degrees |
Returns: the equivalent angle in radians
RadToDeg
pub func RadToDeg(x: float64) -> float64
pub func RadToDeg(x: float32) -> float32
Converts an angle from radians to degrees.
The conversion scales by the nearest float64 to 180 / Pi, making RadToDeg(Pi) exactly 180.0. A signed zero
keeps its sign, infinities keep their sign, and a NaN remains a NaN.
| Overload | Summary |
|---|---|
pub func RadToDeg(x: float64) -> float64 | Converts an angle from radians to degrees. |
pub func RadToDeg(x: float32) -> float32 | Converts an angle from radians to degrees at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | angle in radians |
Returns: the equivalent angle in degrees
ArcCos
pub func ArcCos(x: float64) -> float64
pub func ArcCos(x: float32) -> float32
Computes the inverse cosine of x in radians.
The result lies in [0, Pi]: 1.0 maps to zero, either signed zero maps to Pi / 2, and -1.0 maps to Pi. An
input outside [-1, 1] returns a NaN, and a NaN remains a NaN.
| Overload | Summary |
|---|---|
pub func ArcCos(x: float64) -> float64 | Computes the inverse cosine of x in radians. |
pub func ArcCos(x: float32) -> float32 | Computes the inverse cosine of x in radians at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | cosine value to invert |
Returns: the angle in radians whose cosine is x, or a NaN when x is outside the function's domain
ArcCot
pub func ArcCot(x: float64) -> float64
pub func ArcCot(x: float32) -> float32
Computes the inverse cotangent of x in radians.
The result lies in [0, Pi]: positive infinity maps to zero, either signed zero maps to Pi / 2, and negative
infinity maps to Pi. A NaN remains a NaN.
| Overload | Summary |
|---|---|
pub func ArcCot(x: float64) -> float64 | Computes the inverse cotangent of x in radians. |
pub func ArcCot(x: float32) -> float32 | Computes the inverse cotangent of x in radians at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | cotangent value to invert |
Returns: the angle in radians whose cotangent is x
ArcSin
pub func ArcSin(x: float64) -> float64
pub func ArcSin(x: float32) -> float32
Computes the inverse sine of x in radians.
The result lies in [-Pi / 2, Pi / 2]. A signed zero returns itself, either endpoint maps to the matching endpoint
of the result range, an input outside [-1, 1] returns a NaN, and a NaN remains a NaN.
| Overload | Summary |
|---|---|
pub func ArcSin(x: float64) -> float64 | Computes the inverse sine of x in radians. |
pub func ArcSin(x: float32) -> float32 | Computes the inverse sine of x in radians at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | sine value to invert |
Returns: the angle in radians whose sine is x, or a NaN when x is outside the function's domain
ArcTan
pub func ArcTan(x: float64) -> float64
pub func ArcTan(x: float32) -> float32
Computes the inverse tangent of x in radians.
The result lies in [-Pi / 2, Pi / 2]. A signed zero returns itself, infinities approach the matching endpoint, and
a NaN remains a NaN.
| Overload | Summary |
|---|---|
pub func ArcTan(x: float64) -> float64 | Computes the inverse tangent of x in radians. |
pub func ArcTan(x: float32) -> float32 | Computes the inverse tangent of x in radians at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | tangent value to invert |
Returns: the angle in radians whose tangent is x
ArcTan2
pub func ArcTan2(y: float64, x: float64) -> float64
pub func ArcTan2(y: float32, x: float32) -> float32
The angle from the positive x axis to the point (x, y), in radians, in (-Pi, Pi].
The sign of y decides the sign of the result, including when y is a zero — which is what makes the function
continuous as a point crosses the negative x axis from below, and why a signed zero matters here more than almost
anywhere else.
| Overload | Summary |
|---|---|
pub func ArcTan2(y: float64, x: float64) -> float64 | The angle from the positive x axis to the point (x, y), in radians, in (-Pi, Pi]. |
pub func ArcTan2(y: float32, x: float32) -> float32 | Computes the angle from the positive x axis to (x, y) at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
y | float64 / float32 | vertical coordinate |
x | float64 / float32 | horizontal coordinate |
Returns: the signed angle from the positive x axis to (x, y)
Cos
pub func Cos(x: float64) -> float64
pub func Cos(x: float32) -> float32
Computes the cosine of x, where x is in radians.
The error is at most one ulp for every finite argument. Exact argument reduction keeps a large angle no less
accurate than a small one. Either signed zero returns 1.0; an infinity returns a NaN, and a NaN remains a NaN.
| Overload | Summary |
|---|---|
pub func Cos(x: float64) -> float64 | Computes the cosine of x, where x is in radians. |
pub func Cos(x: float32) -> float32 | Computes the cosine of x at float32 precision, where x is in radians. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | angle in radians |
Returns: the cosine of x, in [-1, 1], or a NaN when x is not finite
Cotan
pub func Cotan(x: float64) -> float64
pub func Cotan(x: float32) -> float32
Computes the cotangent of x, where x is in radians.
The reciprocal is computed directly instead of as 1 / Tan(x), avoiding a second rounding near a pole. A signed
zero maps to an infinity with the same sign; an infinite input returns a NaN, and a NaN remains a NaN.
| Overload | Summary |
|---|---|
pub func Cotan(x: float64) -> float64 | Computes the cotangent of x, where x is in radians. |
pub func Cotan(x: float32) -> float32 | Computes the cotangent of x at float32 precision, where x is in radians. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | angle in radians |
Returns: the cotangent of x, or a NaN when x is not finite
Sin
pub func Sin(x: float64) -> float64
pub func Sin(x: float32) -> float32
Computes the sine of x, where x is in radians.
The error is at most one ulp for every finite argument. Exact argument reduction keeps a large angle no less
accurate than a small one. A signed zero returns itself; an infinity returns a NaN, and a NaN remains a NaN.
| Overload | Summary |
|---|---|
pub func Sin(x: float64) -> float64 | Computes the sine of x, where x is in radians. |
pub func Sin(x: float32) -> float32 | Computes the sine of x at float32 precision, where x is in radians. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | angle in radians |
Returns: the sine of x, in [-1, 1], or a NaN when x is not finite
SinCos
pub func SinCos(angle: float64) -> (float64, float64)
pub func SinCos(angle: float32) -> (float32, float32)
Computes the sine and cosine of angle from one argument reduction.
Returns (sine, cosine). Equivalent to calling Sin and Cos separately, at roughly half the cost.
| Overload | Summary |
|---|---|
pub func SinCos(angle: float64) -> (float64, float64) | Computes the sine and cosine of angle from one argument reduction. |
pub func SinCos(angle: float32) -> (float32, float32) | Computes the sine and cosine of angle at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
angle | float64 / float32 | angle in radians |
Returns: (sine, cosine) for angle
Tan
pub func Tan(x: float64) -> float64
pub func Tan(x: float32) -> float32
Computes the tangent of x, where x is in radians.
The error is at most one ulp for finite arguments away from poles. Exact argument reduction retains all available
information near an odd multiple of Pi / 2. A signed zero returns itself; an infinity returns a NaN, and a NaN
remains a NaN.
| Overload | Summary |
|---|---|
pub func Tan(x: float64) -> float64 | Computes the tangent of x, where x is in radians. |
pub func Tan(x: float32) -> float32 | Computes the tangent of x at float32 precision, where x is in radians. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | angle in radians |
Returns: the tangent of x, or a NaN when x is not finite