Skip to content

Commit 5398d47

Browse files
authored
Implement two arrays binary float fn
1 parent 3ce0134 commit 5398d47

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/numeric/impl_float_maths.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
#[cfg(feature = "std")]
44
use num_traits::Float;
5+
use std::borrow::Borrow;
56

67
use crate::imp_prelude::*;
8+
use crate::IntoNdProducer;
79

810
#[cfg(feature = "std")]
911
macro_rules! boolean_ops {
@@ -50,6 +52,18 @@ macro_rules! binary_ops {
5052
};
5153
}
5254

55+
#[cfg(feature = "std")]
56+
macro_rules! binary_ops_array {
57+
($($(#[$meta:meta])* fn $fn_use:ident($ty:ty) as $fn_name:ident)+) => {
58+
$($(#[$meta])*
59+
#[must_use = "method returns a new array and does not mutate the original value"]
60+
pub fn $fn_name<P>(&self, rhs: P) -> Array<A, D>
61+
where P: IntoNdProducer<Dim = D, Item: Borrow<$ty>> {
62+
$crate::Zip::from(self).and(rhs).map_collect(|a, b| A::$fn_use(*a, *b.borrow()))
63+
})+
64+
};
65+
}
66+
5367
/// # Element-wise methods for float arrays
5468
///
5569
/// Element-wise math functions for any array type that contains float number.
@@ -157,6 +171,22 @@ where
157171
fn abs_sub(A)
158172
/// Length of the hypotenuse of a right-angle triangle of each element
159173
fn hypot(A)
174+
/// Four quadrant arctangent of each element in radians.
175+
fn atan2(A)
176+
}
177+
binary_ops_array! {
178+
/// Integer power of each element.
179+
fn powi(i32) as powi_all
180+
/// Float power of each element.
181+
fn powf(A) as powf_all
182+
/// Logarithm of each element with respect to an arbitrary base.
183+
fn log(A) as log_all
184+
/// The positive difference between given number and each element.
185+
fn abs_sub(A) as abs_sub_all
186+
/// Length of the hypotenuse of a right-angle triangle of each element
187+
fn hypot(A) as hypot_all
188+
/// Four quadrant arctangent of each element in radians.
189+
fn atan2(A) as atan2_all
160190
}
161191

162192
/// Square (two powers) of each element.

0 commit comments

Comments
 (0)