Trigonometry v0.1.0

Source
Sine, cosine, tangent, their inverses, and conversion between degrees and radians.

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.

OverloadSummary
pub func DegToRad(x: float64) -> float64Converts an angle from degrees to radians.
pub func DegToRad(x: float32) -> float32Converts an angle from degrees to radians at float32 precision.

Source

Parameters

NameTypeDescription
xfloat64 / float32angle 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.

OverloadSummary
pub func RadToDeg(x: float64) -> float64Converts an angle from radians to degrees.
pub func RadToDeg(x: float32) -> float32Converts an angle from radians to degrees at float32 precision.

Source

Parameters

NameTypeDescription
xfloat64 / float32angle 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.

OverloadSummary
pub func ArcCos(x: float64) -> float64Computes the inverse cosine of x in radians.
pub func ArcCos(x: float32) -> float32Computes the inverse cosine of x in radians at float32 precision.

Source

Parameters

NameTypeDescription
xfloat64 / float32cosine 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.

OverloadSummary
pub func ArcCot(x: float64) -> float64Computes the inverse cotangent of x in radians.
pub func ArcCot(x: float32) -> float32Computes the inverse cotangent of x in radians at float32 precision.

Source

Parameters

NameTypeDescription
xfloat64 / float32cotangent 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.

OverloadSummary
pub func ArcSin(x: float64) -> float64Computes the inverse sine of x in radians.
pub func ArcSin(x: float32) -> float32Computes the inverse sine of x in radians at float32 precision.

Source

Parameters

NameTypeDescription
xfloat64 / float32sine 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.

OverloadSummary
pub func ArcTan(x: float64) -> float64Computes the inverse tangent of x in radians.
pub func ArcTan(x: float32) -> float32Computes the inverse tangent of x in radians at float32 precision.

Source

Parameters

NameTypeDescription
xfloat64 / float32tangent 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.

OverloadSummary
pub func ArcTan2(y: float64, x: float64) -> float64The angle from the positive x axis to the point (x, y), in radians, in (-Pi, Pi].
pub func ArcTan2(y: float32, x: float32) -> float32Computes the angle from the positive x axis to (x, y) at float32 precision.

Source

Parameters

NameTypeDescription
yfloat64 / float32vertical coordinate
xfloat64 / float32horizontal 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.

OverloadSummary
pub func Cos(x: float64) -> float64Computes the cosine of x, where x is in radians.
pub func Cos(x: float32) -> float32Computes the cosine of x at float32 precision, where x is in radians.

Source

Parameters

NameTypeDescription
xfloat64 / float32angle 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.

OverloadSummary
pub func Cotan(x: float64) -> float64Computes the cotangent of x, where x is in radians.
pub func Cotan(x: float32) -> float32Computes the cotangent of x at float32 precision, where x is in radians.

Source

Parameters

NameTypeDescription
xfloat64 / float32angle 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.

OverloadSummary
pub func Sin(x: float64) -> float64Computes the sine of x, where x is in radians.
pub func Sin(x: float32) -> float32Computes the sine of x at float32 precision, where x is in radians.

Source

Parameters

NameTypeDescription
xfloat64 / float32angle 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.

OverloadSummary
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.

Source

Parameters

NameTypeDescription
anglefloat64 / float32angle 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.

OverloadSummary
pub func Tan(x: float64) -> float64Computes the tangent of x, where x is in radians.
pub func Tan(x: float32) -> float32Computes the tangent of x at float32 precision, where x is in radians.

Source

Parameters

NameTypeDescription
xfloat64 / float32angle in radians

Returns: the tangent of x, or a NaN when x is not finite