A comprehensive Rust math library providing numpy-style mathematical functions for all primitive numeric types.
sin,cos,tan— Standard trigonometric functionsarcsin/asin,arccos/acos,arctan/atan— Inverse trigonometric functionshypot— Hypotenuse (sqrt(x² + y²))arctan2/atan2— Four-quadrant arctangentdegrees/rad2deg,radians/deg2rad— Angle conversionsunwrap— Unwrap phase angles
sinh,cosh,tanh— Hyperbolic functionsarcsinh/asinh,arccosh/acosh,arctanh/atanh— Inverse hyperbolic functions
round/around— Round to nearest (ties away from zero)rint— Round to nearest (ties to even, banker's rounding)fix,trunc— Round toward zerofloor— Round toward negative infinityceil— Round toward positive infinity
sum,prod— Sum and product of elementsnansum,nanprod— NaN-aware sum and productcumsum/cumulative_sum,cumprod/cumulative_prod— Cumulative operationsnancumsum,nancumprod— NaN-aware cumulative operationsdiff— N-th discrete differenceediff1d— Consecutive differences with paddinggradient— Numerical gradienttrapezoid— Trapezoidal integration
exp,expm1,exp2— Exponential functionslog,log10,log2,log1p— Logarithmic functionslogaddexp,logaddexp2— Log-sum-exp (overflow-safe)
add,subtract,multiply,divide— Element-wise arithmeticpower/pow,float_power— Element-wise exponentiationfloor_divide,true_divide— Division variantsfmod/mod_fn/remainder— Remainder operationsmodf— Fractional and integral partsdivmod— Quotient and remainderreciprocal,positive,negative— Unary operations
signbit— Sign bit inspectioncopysign— Sign copyingfrexp— Mantissa/exponent decompositionldexp— Multiply by power of twonextafter— Next representable valuespacing— Distance to adjacent value
max/amax,min/amin— Array maximum/minimummaximum,minimum— Element-wise maximum/minimumfmax,fmin— NaN-aware element-wise operationsnanmax,nanmin— NaN-tolerant array operations
angle— Phase anglereal,imag— Real/imaginary partsconj/conjugate— Complex conjugate
convolve— Discrete linear convolutionclip— Limit values to a rangesqrt,cbrt— Square root and cube rootsquare— Element-wise squareabsolute/fabs— Absolute valuesign— Sign indicationheaviside— Heaviside step functionnan_to_num— Replace NaN/Inf with specified valuesreal_if_close— Return real parts if imaginary parts are near zerointerp— Linear interpolationsinc— Normalized sinc functioni0— Modified Bessel function of the first kind, order 0
gcd,lcm— Greatest common divisor and least common multiplegcd_ew,lcm_ew— Element-wise GCD/LCMmean,median,mode— Statistical measures
Add to your Cargo.toml:
[dependencies]
mathevil = "0.2"use mathevil::*;
// Trigonometric
let s = sin([0.0, std::f64::consts::FRAC_PI_2]);
assert_eq!(s, vec![0.0, 1.0]);
// Arithmetic
let r = add([1.0, 2.0, 3.0], [4.0, 5.0, 6.0]);
assert_eq!(r, vec![5.0, 7.0, 9.0]);
// Rounding
let r = floor([1.7, -1.2, 3.0]);
assert_eq!(r, vec![1.0, -2.0, 3.0]);
// Exponents
let e = exp([0.0, 1.0, 2.0]);
// Extrema
let m = max([1.0, 5.0, 3.0]);
assert_eq!(m, Some(5.0));
// Interpolation
let result = interp([0.5, 1.5], [0.0, 1.0, 2.0], [0.0, 2.0, 4.0], None, None);
assert_eq!(result, vec![1.0, 3.0]);All functions are element-wise and work on any iterator of Numeric types (all Rust primitive numeric types: i8–i128, u8–u128, f32, f64, isize, usize). Results are returned as Vec<f64>.
MIT