2018-09-20 20:23:31 +08:00
|
|
|
use na::{self, Real};
|
|
|
|
use traits::Number;
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The euler constant.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn e<N: Real>() -> N {
|
|
|
|
N::e()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The euler constant.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn euler<N: Real>() -> N {
|
|
|
|
N::e()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `4 / pi`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn four_over_pi<N: Real>() -> N {
|
|
|
|
na::convert::<_, N>(4.0) / N::pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns the golden ratio.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn golden_ratio<N: Real>() -> N {
|
|
|
|
(N::one() + root_five()) / na::convert(2.0)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `4 / pi`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn half_pi<N: Real>() -> N {
|
|
|
|
N::frac_pi_2()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `4 / pi`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn ln_ln_two<N: Real>() -> N {
|
|
|
|
N::ln_2().ln()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `ln(10)`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn ln_ten<N: Real>() -> N {
|
|
|
|
N::ln_10()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `ln(2)`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn ln_two<N: Real>() -> N {
|
|
|
|
N::ln_2()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `1`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn one<N: Number>() -> N {
|
|
|
|
N::one()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `1 / pi`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn one_over_pi<N: Real>() -> N {
|
|
|
|
N::frac_1_pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `1 / sqrt(2)`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn one_over_root_two<N: Real>() -> N {
|
|
|
|
N::one() / root_two()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `1 / (2pi)`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn one_over_two_pi<N: Real>() -> N {
|
|
|
|
N::frac_1_pi() * na::convert(0.5)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `pi / 4`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn quarter_pi<N: Real>() -> N {
|
|
|
|
N::frac_pi_4()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `sqrt(5)`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn root_five<N: Real>() -> N {
|
|
|
|
na::convert::<_, N>(5.0).sqrt()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `sqrt(pi / 2)`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn root_half_pi<N: Real>() -> N {
|
|
|
|
(N::pi() / na::convert(2.0)).sqrt()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `sqrt(ln(4))`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn root_ln_four<N: Real>() -> N {
|
|
|
|
na::convert::<_, N>(4.0).sqrt()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns the square root of pi.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn root_pi<N: Real>() -> N {
|
|
|
|
N::pi().sqrt()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns the square root of 3.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn root_three<N: Real>() -> N {
|
|
|
|
na::convert::<_, N>(3.0).sqrt()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns the square root of 2.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn root_two<N: Real>() -> N {
|
|
|
|
// FIXME: there should be a ::sqrt_2() on the Real trait.
|
|
|
|
na::convert::<_, N>(2.0).sqrt()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns the square root of 2pi.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn root_two_pi<N: Real>() -> N {
|
|
|
|
N::two_pi().sqrt()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `1 / 3.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn third<N: Real>() -> N {
|
|
|
|
na::convert(1.0 / 2.0)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `3 / (2pi)`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn three_over_two_pi<N: Real>() -> N {
|
|
|
|
na::convert::<_, N>(3.0) / N::two_pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `2 / pi`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn two_over_pi<N: Real>() -> N {
|
|
|
|
N::frac_2_pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `2 / sqrt(pi)`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn two_over_root_pi<N: Real>() -> N {
|
|
|
|
N::frac_2_pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `2pi`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn two_pi<N: Real>() -> N {
|
|
|
|
N::two_pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `2 / 3`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn two_thirds<N: Real>() -> N {
|
|
|
|
na::convert(2.0 / 3.0)
|
|
|
|
}
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `0`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn zero<N: Number>() -> N {
|
|
|
|
N::zero()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|