Skip to content

Commit

Permalink
Apply partial suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
KmolYuan authored and bluss committed Nov 8, 2021
1 parent 3296660 commit 6b25dca
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/impl_float_maths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ use crate::imp_prelude::*;
macro_rules! boolean_op {
($($(#[$meta1:meta])* fn $id1:ident $(#[$meta2:meta])* fn $id2:ident -> $func:ident)+) => {
$($(#[$meta1])*
#[must_use = "method returns a new array and does not mutate the original value"]
pub fn $id1(&self) -> Array<bool, D> {
self.mapv(A::$func)
}
$(#[$meta2])*
#[must_use = "method returns a new boolean value and does not mutate the original value"]
pub fn $id2(&self) -> bool {
self.mapv(A::$func).iter().any(|&b|b)
self.mapv(A::$func).iter().any(|&b| b)
})+
};
}

macro_rules! unary_op {
($($(#[$meta:meta])* fn $id:ident)+) => {
$($(#[$meta])*
#[must_use = "method returns a new array and does not mutate the original value"]
pub fn $id(&self) -> Array<A, D> {
self.mapv(A::$id)
})+
Expand All @@ -29,6 +32,7 @@ macro_rules! unary_op {
macro_rules! binary_op {
($($(#[$meta:meta])* fn $id:ident($ty:ty))+) => {
$($(#[$meta])*
#[must_use = "method returns a new array and does not mutate the original value"]
pub fn $id(&self, rhs: $ty) -> Array<A, D> {
self.mapv(|v| A::$id(v, rhs))
})+
Expand All @@ -41,19 +45,19 @@ macro_rules! binary_op {
impl<A, S, D> ArrayBase<S, D>
where
A: Float,
S: RawData<Elem = A> + Data,
S: Data<Elem = A>,
D: Dimension,
{
boolean_op! {
/// If the number is `NaN` (not a number), then `true` is returned for each element.
fn is_nan
/// Return `true` if any element is `NaN` (not a number).
fn is_nan_any -> is_nan
fn is_any_nan -> is_nan

/// If the number is infinity, then `true` is returned for each element.
fn is_infinite
/// Return `true` if any element is infinity.
fn is_infinite_any -> is_infinite
fn is_any_infinite -> is_infinite
}
unary_op! {
/// The largest integer less than or equal to each element.
Expand Down Expand Up @@ -87,7 +91,7 @@ where
/// Square root of each element.
fn sqrt

/// `e^x` of each element. (Exponential function)
/// `e^x` of each element (exponential function).
fn exp

/// `2^x` of each element.
Expand All @@ -105,13 +109,13 @@ where
/// Cubic root of each element.
fn cbrt

/// Sine of each element. (in radians)
/// Sine of each element (in radians).
fn sin

/// Cosine of each element. (in radians)
/// Cosine of each element (in radians).
fn cos

/// Tangent of each element. (in radians)
/// Tangent of each element (in radians).
fn tan

/// Converts radians to degrees for each element.
Expand All @@ -136,9 +140,10 @@ where
fn abs_sub(A)
}

/// Square of each element.
pub fn square(&self) -> Array<A, D> {
self.mapv(|v| v * v)
/// Square (two powers) of each element.
#[must_use = "method returns a new array and does not mutate the original value"]
pub fn pow2(&self) -> Array<A, D> {
self.mapv(|v: A| v * v)
}

/// Limit the values for each element.
Expand Down

0 comments on commit 6b25dca

Please sign in to comment.