nalgebra/nalgebra-glm/src/exponential.rs

73 lines
1.7 KiB
Rust
Raw Normal View History

2019-03-23 21:29:07 +08:00
use crate::aliases::TVec;
2018-10-22 04:11:27 +08:00
use na::{DefaultAllocator, Real};
2019-03-23 21:29:07 +08:00
use crate::traits::{Alloc, Dimension};
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)
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> {
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)
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> {
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)
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> {
v.map(|x| N::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)
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> {
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)
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> {
v.map(|x| x.log2())
}
2018-09-22 19:21:02 +08:00
/// Component-wise power.
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> {
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)
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> {
v.map(|x| x.sqrt())
}