Powers and roots v0.1.0

Source
Raising to a power, square and cube roots, and the hypotenuse.

Cbrt

pub func Cbrt(x: float64) -> float64
pub func Cbrt(x: float32) -> float32

Computes the real cube root of x. The error is at most one ulp. Negative inputs produce negative roots, a signed zero or infinity returns itself, and a NaN remains a NaN.

OverloadSummary
pub func Cbrt(x: float64) -> float64Computes the real cube root of x.
pub func Cbrt(x: float32) -> float32Computes the real cube root of x at float32 precision.

Source

Parameters

NameTypeDescription
xfloat64 / float32value whose cube root is computed

Returns: the real cube root of x

Hypot

pub func Hypot(x: float64, y: float64) -> float64
pub func Hypot(x: float32, y: float32) -> float32

Computes the Euclidean length Sqrt(x * x + y * y) without intermediate overflow or underflow. The error is at most one ulp. An infinity in either argument returns positive infinity even when the other is a NaN; otherwise a NaN remains a NaN.

OverloadSummary
pub func Hypot(x: float64, y: float64) -> float64Computes the Euclidean length Sqrt(x * x + y * y) without intermediate overflow or underflow.
pub func Hypot(x: float32, y: float32) -> float32Computes the Euclidean length of (x, y) at float32 precision.

Source

Parameters

NameTypeDescription
xfloat64 / float32first Cartesian component
yfloat64 / float32second Cartesian component

Returns: the non-negative length of (x, y)

Pow

pub func Pow(x: float64, y: float64) -> float64
pub func Pow(x: float32, y: float32) -> float32

Raises x to the power y. The error is at most one ulp. A negative base requires an integer exponent; otherwise the result is a NaN. PowInteger is both faster and able to preserve exact results when the exponent is an integer.

OverloadSummary
pub func Pow(x: float64, y: float64) -> float64Raises x to the power y.
pub func Pow(x: float32, y: float32) -> float32Raises x to the power y at float32 precision.

Source

Parameters

NameTypeDescription
xfloat64 / float32base
yfloat64 / float32exponent

Returns: x raised to y

PowInteger

pub func PowInteger(
    base: float64,
    exponent: int64
) -> float64

pub func PowInteger(
    base: float32,
    exponent: int64
) -> float32

base raised to the integer power exponent. A zero exponent gives one for every base, including zero and a NaN, which is the same rule Pow follows: the empty product is one. A negative exponent takes the reciprocal at the end rather than dividing as it goes, which keeps the intermediates as large as possible and loses the least.

OverloadSummary
pub func PowInteger(base: float64, exponent: int64) -> float64base raised to the integer power exponent.
pub func PowInteger(base: float32, exponent: int64) -> float32Raises base to the integer power exponent at float32 precision.

Source

Parameters

NameTypeDescription
basefloat64 / float32value to raise
exponentint64integer power

Returns: base raised to exponent

Sqrt

pub func Sqrt(x: float32) -> float32
pub func Sqrt(x: float64) -> float64

Computes the correctly rounded square root of x at float32 precision. A signed zero, positive infinity, or NaN passes through; a negative finite value returns a NaN.

OverloadSummary
pub func Sqrt(x: float32) -> float32Computes the correctly rounded square root of x at float32 precision.
pub func Sqrt(x: float64) -> float64Computes the correctly rounded square root of x.

Source

Parameters

NameTypeDescription
xfloat32 / float64value whose square root is computed

Returns: the non-negative square root of x, or a NaN when x is negative