Trait arr_rs::math::operations::rounding::ArrayRounding
source · pub trait ArrayRounding<N: Numeric>where
Self: Sized + Clone,{
// Required methods
fn round(&self, decimals: &Array<isize>) -> Result<Array<N>, ArrayError>;
fn around(&self, decimals: &Array<isize>) -> Result<Array<N>, ArrayError>;
fn rint(&self) -> Result<Array<N>, ArrayError>;
fn fix(&self) -> Result<Array<N>, ArrayError>;
fn trunc(&self) -> Result<Array<N>, ArrayError>;
fn floor(&self) -> Result<Array<N>, ArrayError>;
fn ceil(&self) -> Result<Array<N>, ArrayError>;
}
Expand description
ArrayTrait - Array Rounding functions
Required Methods§
sourcefn round(&self, decimals: &Array<isize>) -> Result<Array<N>, ArrayError>
fn round(&self, decimals: &Array<isize>) -> Result<Array<N>, ArrayError>
Evenly round to the given number of decimals
Arguments
decimals
- Number of decimal places to round to (default: 0). If decimals is negative, it specifies the number of positions to the left of the decimal point
Examples
use arr_rs::prelude::*;
let arr = Array::flat(vec![2.01, 4.6, 8.0010, 22.234]);
assert_eq!(Array::flat(vec![2., 4.6, 8.001, 20.]), arr.round(&Array::flat(vec![0, 1, 3, -1]).unwrap()));
sourcefn around(&self, decimals: &Array<isize>) -> Result<Array<N>, ArrayError>
fn around(&self, decimals: &Array<isize>) -> Result<Array<N>, ArrayError>
Evenly round to the given number of decimals. alias on round
Arguments
decimals
- Number of decimal places to round to (default: 0). If decimals is negative, it specifies the number of positions to the left of the decimal point
Examples
use arr_rs::prelude::*;
let arr = Array::flat(vec![2.01, 4.6, 8.0010, 22.234]);
assert_eq!(Array::flat(vec![2., 4.6, 8.001, 20.]), arr.around(&Array::flat(vec![0, 1, 3, -1]).unwrap()));
sourcefn rint(&self) -> Result<Array<N>, ArrayError>
fn rint(&self) -> Result<Array<N>, ArrayError>
Round elements of the array to the nearest integer
Examples
use arr_rs::prelude::*;
let arr = Array::flat(vec![2.01, 4.6, 8.0010, 22.234]);
assert_eq!(Array::flat(vec![2., 5., 8., 22.]), arr.rint());
sourcefn fix(&self) -> Result<Array<N>, ArrayError>
fn fix(&self) -> Result<Array<N>, ArrayError>
Round to nearest integer towards zero
Examples
use arr_rs::prelude::*;
let arr = Array::flat(vec![2.01, 4.6, -1.6, -2.2]);
assert_eq!(Array::flat(vec![2., 4., -1., -2.]), arr.fix());
sourcefn trunc(&self) -> Result<Array<N>, ArrayError>
fn trunc(&self) -> Result<Array<N>, ArrayError>
Round to nearest integer towards zero
Examples
use arr_rs::prelude::*;
let arr = Array::flat(vec![2.01, 4.6, -1.6, -2.2]);
assert_eq!(Array::flat(vec![2., 4., -1., -2.]), arr.fix());