[−][src]Crate spinoso_math
The Ruby Math module.
The Math module contains module functions for basic trigonometric and
transcendental functions. See class Float
for a list of constants that
define Ruby's floating point accuracy.
This crate defines math operations as free functions. These functions differ
from those defined in Rust core
by returning a DomainError
when an
input is outside of the domain of the function and results in NaN
.
spinoso-math
assumes the Ruby VM uses double precision f64
floats.
Examples
Compute the hypotenuse:
use spinoso_math as math; assert_eq!(math::hypot(3.0, 4.0), 5.0);
Compute log with respect to the base 10 and handle domain errors:
use spinoso_math as math; assert_eq!(math::log10(1.0), Ok(0.0)); assert_eq!(math::log10(10.0), Ok(1.0)); assert_eq!(math::log10(1e100), Ok(100.0)); assert_eq!(math::log10(0.0), Ok(f64::NEG_INFINITY)); assert!(math::log10(-0.1).is_err()); // A NaN return value is distinct from a `DomainError`. assert!(matches!(math::log10(f64::NAN), Ok(result) if result.is_nan()));
no_std
This crate is no_std
compatible when built without the std
feature. This
crate does not depend on alloc
.
Crate features
All features are enabled by default.
- full - Enables implementations of math functions that do not have
implementations in Rust
core
. Dropping this feature removes thelibm
dependency. - std - Enables a dependency on the Rust Standard Library. Activating
this feature enables
std::error::Error
impls on error types in this crate.
Structs
DomainError | Error that indicates a math function evaluated to an out of range value. |
Math | A handle to the |
NotImplementedError | Error that indicates a |
Enums
Error | Sum type of all errors possibly returned from |
Constants
E | Euler's number (e) |
PI | Archimedes' constant (π) |
Functions
acos | Computes the arccosine of the given value. Returns results in the range
|
acosh | Computes the inverse hyperbolic cosine of the given value. |
asin | Computes the arcsine of the given value. Returns results in the range
|
asinh | Computes the inverse hyperbolic sine of the given value. |
atan | Computes the arctangent of the given value. Returns results in the range
|
atan2 | Computes the four quadrant arctangent of |
atanh | Computes the inverse hyperbolic tangent of the given value. |
cbrt | Returns the cube root of the given value. |
cos | Computes the cosine of the given value (expressed in radians). Returns
values in the range |
cosh | Computes the hyperbolic cosine of the given value (expressed in radians). |
erf | Calculates the error function of the given value. |
erfc | Calculates the complementary error function of the given value. |
exp | Returns |
frexp | Returns a tuple array containing the normalized fraction (a Float) and exponent (an Integer) of the given value. |
gamma | Calculates the gamma function of the given value. |
hypot | Returns |
ldexp | Returns the value of |
lgamma | Calculates the logarithmic gamma of value and the sign of gamma of value. |
log | Returns the logarithm of the number with respect to an arbitrary base. |
log2 | Returns the base 2 logarithm of the number. |
log10 | Returns the base 10 logarithm of the number. |
sin | Computes the sine of the given value (expressed in radians). Returns a Float
in the range |
sinh | Computes the hyperbolic sine of the given value (expressed in radians). |
sqrt | Returns the non-negative square root of the given value. |
tan | Computes the tangent of the given value (expressed in radians). |
tanh | Computes the hyperbolic tangent of the given value (expressed in radians). |