2018-09-23 20:48:45 +08:00
|
|
|
use aliases::TVec;
|
2018-10-22 04:11:27 +08:00
|
|
|
use na::{DefaultAllocator, Real};
|
2018-09-20 20:23:31 +08:00
|
|
|
use traits::{Alloc, Dimension};
|
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:
|
|
|
|
///
|
|
|
|
/// * [`exp2`](fn.exp2.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn exp<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Alloc<N, 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:
|
|
|
|
///
|
|
|
|
/// * [`exp`](fn.exp.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn exp2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Alloc<N, 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:
|
|
|
|
///
|
|
|
|
/// * [`sqrt`](fn.sqrt.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn inversesqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
v.map(|x| N::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:
|
|
|
|
///
|
|
|
|
/// * [`log2`](fn.log2.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn log<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Alloc<N, 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:
|
|
|
|
///
|
|
|
|
/// * [`log`](fn.log.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn log2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Alloc<N, 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.
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn pow<N: Real, D: Dimension>(base: &TVec<N, D>, exponent: &TVec<N, D>) -> TVec<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Alloc<N, 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:
|
|
|
|
///
|
|
|
|
/// * [`exp`](fn.exp.html)
|
|
|
|
/// * [`exp2`](fn.exp2.html)
|
|
|
|
/// * [`inversesqrt`](fn.inversesqrt.html)
|
|
|
|
/// * [`pow`](fn.pow.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn sqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
v.map(|x| x.sqrt())
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|