Powers and roots v0.1.0
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.
| Overload | Summary |
|---|---|
pub func Cbrt(x: float64) -> float64 | Computes the real cube root of x. |
pub func Cbrt(x: float32) -> float32 | Computes the real cube root of x at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | value 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.
| Overload | Summary |
|---|---|
pub func Hypot(x: float64, y: float64) -> float64 | Computes the Euclidean length Sqrt(x * x + y * y) without intermediate overflow or underflow. |
pub func Hypot(x: float32, y: float32) -> float32 | Computes the Euclidean length of (x, y) at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | first Cartesian component |
y | float64 / float32 | second 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.
| Overload | Summary |
|---|---|
pub func Pow(x: float64, y: float64) -> float64 | Raises x to the power y. |
pub func Pow(x: float32, y: float32) -> float32 | Raises x to the power y at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | base |
y | float64 / float32 | exponent |
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.
| Overload | Summary |
|---|---|
pub func PowInteger(base: float64, exponent: int64) -> float64 | base raised to the integer power exponent. |
pub func PowInteger(base: float32, exponent: int64) -> float32 | Raises base to the integer power exponent at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
base | float64 / float32 | value to raise |
exponent | int64 | integer 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.
| Overload | Summary |
|---|---|
pub func Sqrt(x: float32) -> float32 | Computes the correctly rounded square root of x at float32 precision. |
pub func Sqrt(x: float64) -> float64 | Computes the correctly rounded square root of x. |
Parameters
| Name | Type | Description |
|---|---|---|
x | float32 / float64 | value whose square root is computed |
Returns: the non-negative square root of x, or a NaN when x is negative