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