nalgebra/nalgebra-glm/src/exponential.rs

65 lines
1.5 KiB
Rust
Raw Normal View History

2019-03-23 21:29:07 +08:00
use crate::aliases::TVec;
2021-04-11 17:00:38 +08:00
use na::RealField;
2018-09-22 19:21:02 +08:00
/// Component-wise exponential.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`exp2`](fn.exp2.html)
2021-04-11 17:00:38 +08:00
pub fn exp<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| x.exp())
}
2018-09-22 19:21:02 +08:00
/// Component-wise base-2 exponential.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`exp`](fn.exp.html)
2021-04-11 17:00:38 +08:00
pub fn exp2<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| x.exp2())
}
/// Compute the inverse of the square root of each component of `v`.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`sqrt`](fn.sqrt.html)
2021-04-11 17:00:38 +08:00
pub fn inversesqrt<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| T::one() / x.sqrt())
}
2018-09-22 19:21:02 +08:00
/// Component-wise logarithm.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`log2`](fn.log2.html)
2021-04-11 17:00:38 +08:00
pub fn log<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| x.ln())
}
2018-09-22 19:21:02 +08:00
/// Component-wise base-2 logarithm.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`log`](fn.log.html)
2021-04-11 17:00:38 +08:00
pub fn log2<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| x.log2())
}
2018-09-22 19:21:02 +08:00
/// Component-wise power.
2021-04-11 17:00:38 +08:00
pub fn pow<T: RealField, const D: usize>(base: &TVec<T, D>, exponent: &TVec<T, D>) -> TVec<T, D> {
base.zip_map(exponent, |b, e| b.powf(e))
}
2018-09-22 19:21:02 +08:00
/// Component-wise square root.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`exp`](fn.exp.html)
/// * [`exp2`](fn.exp2.html)
/// * [`inversesqrt`](fn.inversesqrt.html)
/// * [`pow`](fn.pow.html)
2021-04-11 17:00:38 +08:00
pub fn sqrt<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| x.sqrt())
}