Crate spinoso_math[][src]

Expand description

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 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()));

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 the libm dependency.

Structs

Error that indicates a math function evaluated to an out of range value.

A handle to the Math module.

Error that indicates a Math module function is not implemented.

Enums

Sum type of all errors possibly returned from Math functions.

Constants

Euler’s number (e)

Archimedes’ constant (π)

Functions

Computes the arccosine of the given value. Returns results in the range (0..=PI).

Computes the inverse hyperbolic cosine of the given value.

Computes the arcsine of the given value. Returns results in the range (-PI/2..=PI/2).

Computes the inverse hyperbolic sine of the given value.

Computes the arctangent of the given value. Returns results in the range (-PI/2..=PI/2).

Computes the four quadrant arctangent of value (y) and other (x) in radians.

Computes the inverse hyperbolic tangent of the given value.

Returns the cube root of the given value.

Computes the cosine of the given value (expressed in radians). Returns values in the range -1.0..=1.0.

Computes the hyperbolic cosine of the given value (expressed in radians).

Calculates the error function of the given value.

Calculates the complementary error function of the given value.

Returns e**x.

Returns a tuple array containing the normalized fraction (a Float) and exponent (an Integer) of the given value.

Calculates the gamma function of the given value.

Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle with sides x and y.

Returns the value of fraction * (2**exponent).

Calculates the logarithmic gamma of value and the sign of gamma of value.

Returns the logarithm of the number with respect to an arbitrary base.

Returns the base 2 logarithm of the number.

Returns the base 10 logarithm of the number.

Computes the sine of the given value (expressed in radians). Returns a Float in the range -1.0..=1.0.

Computes the hyperbolic sine of the given value (expressed in radians).

Returns the non-negative square root of the given value.

Computes the tangent of the given value (expressed in radians).

Computes the hyperbolic tangent of the given value (expressed in radians).