2021-08-08 18:59:40 +08:00
|
|
|
use crate::RealNumber;
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-10-16 22:48:31 +08:00
|
|
|
/// The Euler constant.
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// This is a shorthand alias for [`euler()`].
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn e<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::e()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-10-16 22:48:31 +08:00
|
|
|
/// The Euler constant.
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn euler<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::e()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `4 / pi`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn four_over_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
na::convert::<_, T>(4.0) / T::pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns the golden ratio.
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn golden_ratio<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
(T::one() + root_five()) / na::convert(2.0)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 23:36:08 +08:00
|
|
|
/// Returns `pi / 2`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn half_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::frac_pi_2()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 23:36:08 +08:00
|
|
|
/// Returns `ln(ln(2))`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`ln_ten()`]
|
|
|
|
/// * [`ln_two()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn ln_ln_two<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::ln_2().ln()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `ln(10)`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`ln_ln_two()`]
|
|
|
|
/// * [`ln_two()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn ln_ten<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::ln_10()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `ln(2)`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`ln_ln_two()`]
|
|
|
|
/// * [`ln_ten()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn ln_two<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::ln_2()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `1`.
|
2018-09-23 22:22:00 +08:00
|
|
|
pub use na::one;
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `1 / pi`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn one_over_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::frac_1_pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `1 / sqrt(2)`.
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn one_over_root_two<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::one() / root_two()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `1 / (2pi)`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn one_over_two_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::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-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn quarter_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::frac_pi_4()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `sqrt(5)`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`root_three()`]
|
|
|
|
/// * [`root_two()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn root_five<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
na::convert::<_, T>(5.0).sqrt()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `sqrt(pi / 2)`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn root_half_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
(T::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))`.
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn root_ln_four<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
na::convert::<_, T>(4.0).ln().sqrt()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns the square root of pi.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn root_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::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-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`root_five()`]
|
|
|
|
/// * [`root_two()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn root_three<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
na::convert::<_, T>(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-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`root_five()`]
|
|
|
|
/// * [`root_three()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn root_two<T: RealNumber>() -> T {
|
|
|
|
// TODO: there should be a crate::sqrt_2() on the RealNumber trait.
|
2021-04-11 17:00:38 +08:00
|
|
|
na::convert::<_, T>(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-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn root_two_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::two_pi().sqrt()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 23:36:08 +08:00
|
|
|
/// Returns `1 / 3`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`two_thirds()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn third<T: RealNumber>() -> T {
|
2018-09-23 21:59:24 +08:00
|
|
|
na::convert(1.0 / 3.0)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `3 / (2pi)`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn three_over_two_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
na::convert::<_, T>(3.0) / T::two_pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `2 / pi`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn two_over_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::frac_2_pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `2 / sqrt(pi)`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn two_over_root_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::frac_2_sqrt_pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `2pi`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`four_over_pi()`]
|
|
|
|
/// * [`half_pi()`]
|
|
|
|
/// * [`one_over_pi()`]
|
|
|
|
/// * [`one_over_two_pi()`]
|
|
|
|
/// * [`pi()`](crate::pi)
|
|
|
|
/// * [`quarter_pi()`]
|
|
|
|
/// * [`root_half_pi()`]
|
|
|
|
/// * [`root_pi()`]
|
|
|
|
/// * [`root_two_pi()`]
|
|
|
|
/// * [`three_over_two_pi()`]
|
|
|
|
/// * [`two_over_pi()`]
|
|
|
|
/// * [`two_over_root_pi()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn two_pi<T: RealNumber>() -> T {
|
2021-04-11 17:00:38 +08:00
|
|
|
T::two_pi()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `2 / 3`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
2023-08-06 23:25:22 +08:00
|
|
|
/// * [`third()`]
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn two_thirds<T: RealNumber>() -> T {
|
2018-09-20 20:23:31 +08:00
|
|
|
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-10-03 19:28:07 +08:00
|
|
|
pub use na::zero;
|