Crate trig_const

Source
Expand description

§trig-const

Rust implementation of const trig functions.

This is implemented using Taylor series approximations. Correctness is prioritized over speed, especially considering the main use case for this crate is to expose trigonometric functions for compile-time evaluation.

The implemntation was largely inspired by the work of Dr. Austin Henley and Dr. Stephen Marz:

The implementation carries forward the original MIT license contained in the GitHub repo above.

§Project Goals

  • Correctness while const (same result as std within a rounding error)
  • no-std
  • No unsafe

§Requirements

This crate supports any compiler version back to rustc 1.85.0

[dependencies]
trig-const = "0"

§Example

use std::f64::consts::PI;
use trig_const::cos;

const COS_PI: f64 = cos(PI);
assert_eq!(COS_PI, -1.0);
use std::f64::consts::PI;
use trig_const::{atan2, sin};

const SIN_PI_4: f64 = sin(PI / 2.0);
const ATAN2_0_0: f64 = atan2(0.0, 0.0);

fn main() {
    println!("{}\n{}", SIN_PI_4, ATAN2_0_0);
}

Functions§

acos
Arccosine
acosh
Inverse hyperbolic cosine
asin
Arcsine
asinh
Inverse hyperbolic sine
atan
Arctangent
atan2
Arctan2
cos
Cosine
cosh
Hyperbolic Cosine
cot
Cotangent
csc
Cosecant
exp
e^x
expi
x^pow
fabs
factorial
Factorial (x!)
ln
Computes natural log using a port from Rust’s libm
pow
Power function
sec
Secant
sin
Sine
sinh
Hyperbolic Sine
sqrt
Const sqrt function using Newton’s method
tan
Tangent