Trait arr_rs::math::operations::floating::ArrayFloating
source · pub trait ArrayFloating<N: Floating>where
Self: Sized + Clone,{
// Required methods
fn signbit(&self) -> Result<Array<bool>, ArrayError>;
fn copysign(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>;
fn frexp(&self) -> Result<(Array<N>, Array<i32>), ArrayError>;
fn ldexp(&self, other: &Array<i32>) -> Result<Array<N>, ArrayError>;
fn nextafter(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>;
fn spacing(&self) -> Result<Array<N>, ArrayError>;
}
Expand description
ArrayTrait - Array Floating functions
Required Methods§
sourcefn signbit(&self) -> Result<Array<bool>, ArrayError>
fn signbit(&self) -> Result<Array<bool>, ArrayError>
Returns element-wise True where signbit is set (less than zero)
Examples
use arr_rs::prelude::*;
let arr = Array::flat(vec![1., -2., -3., 4.]);
assert_eq!(Array::flat(vec![false, true, true, false]), arr.signbit());
sourcefn copysign(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>
fn copysign(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>
Change the sign of x1 to that of x2, element-wise
Arguments
other
- array to copy sign from
Examples
use arr_rs::prelude::*;
let arr = Array::flat(vec![1., -2., -3., 4.]);
let other = Array::flat(vec![-1., 2., -3., 4.]);
assert_eq!(Array::flat(vec![-1., 2., -3., 4.]), arr.copysign(&other.unwrap()));
sourcefn frexp(&self) -> Result<(Array<N>, Array<i32>), ArrayError>
fn frexp(&self) -> Result<(Array<N>, Array<i32>), ArrayError>
Decompose the elements of x into man and twos exp
Examples
use arr_rs::prelude::*;
let arr = Array::arange(0., 8., None);
let result = arr.frexp().unwrap();
assert_eq!(Array::flat(vec![0., 0.5, 0.5, 0.75, 0.5, 0.625, 0.75, 0.875, 0.5]).unwrap(), result.0);
assert_eq!(Array::flat(vec![0, 1, 2, 2, 3, 3, 3, 3, 4]).unwrap(), result.1);
sourcefn ldexp(&self, other: &Array<i32>) -> Result<Array<N>, ArrayError>
fn ldexp(&self, other: &Array<i32>) -> Result<Array<N>, ArrayError>
Returns x1 * 2**x2, element-wise. Inverse of frexp
Examples
use arr_rs::prelude::*;
let arr = Array::flat(vec![0., 0.5, 0.5, 0.75, 0.5, 0.625, 0.75, 0.875, 0.5]);
let other = Array::flat(vec![0, 1, 2, 2, 3, 3, 3, 3, 4]);
assert_eq!(Array::arange(0., 8., None), arr.ldexp(&other.unwrap()));
sourcefn nextafter(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>
fn nextafter(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>
Return the next floating-point value after x1 towards x2, element-wise
Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![1. + f64::EPSILON, 2. - f64::EPSILON]);
assert_eq!(expected, Array::flat(vec![1., 2.]).nextafter(&Array::flat(vec![2., 1.]).unwrap()));