real: add sin, cos and ln2 functions

This commit is contained in:
2022-08-22 00:37:19 -07:00
parent f0fc324188
commit e32d500f8c

View File

@@ -92,6 +92,12 @@ pub trait Real:
fn powf(self, p: Self) -> Self;
fn sqrt(self) -> Self;
fn sin_cos(self) -> (Self, Self);
fn sin(self) -> Self {
self.sin_cos().0
}
fn cos(self) -> Self {
self.sin_cos().1
}
fn min_max_or_undefined(self, other: Self) -> (Self, Self) {
match self.partial_cmp(&other) {
@@ -127,6 +133,7 @@ pub trait Real:
fn half() -> Self;
fn pi() -> Self;
fn two_pi() -> Self;
fn ln2() -> Self;
/// Speed of light in a vacuum; m/s.
/// Also equal to 1/sqrt(epsilon_0 mu_0)
@@ -172,6 +179,9 @@ macro_rules! decl_consts {
fn two_pi() -> Self {
$wrap(6.283185307179586)
}
fn ln2() -> Self {
$wrap(0.6931471805599453)
}
/// Speed of light in a vacuum; m/s.
/// Also equal to 1/sqrt(epsilon_0 mu_0)
@@ -481,6 +491,9 @@ impl<T: Real> Real for Finite<T> {
fn two_pi() -> Self {
Self::from_primitive(T::two_pi())
}
fn ln2() -> Self {
Self::from_primitive(T::ln2())
}
fn c() -> Self {
Self::from_primitive(T::c())
}