Trait float_approx_math::ApproxCos
source · pub trait ApproxCos {
// Required method
fn approx_cos(self) -> Self;
}Required Methods§
sourcefn approx_cos(self) -> Self
fn approx_cos(self) -> Self
Calculates an approximation of a cosine, using the Z80 / ZX Spectrum algorithm.
https://namoseley.wordpress.com/2012/09/26/arduinoavr-and-zx-spectrum-sin-routines/
This approximation is significantly slower than the built-in cos method in the standard library, however this method can be run at compile-time.
Example
#![feature(const_trait_impl)]
use float_approx_math::ApproxCos;
const X: f32 = 2.0;
let y: f32 = X.approx_cos();
assert!((y - X.cos()).abs() < 0.0000005); // Less than 0.0000005 abs errorObject Safety§
This trait is not object safe.