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§

source

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()));
source

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()));
source

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());
source

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());
source

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());
source

fn floor(&self) -> Result<Array<N>, ArrayError>

Return the floor of the input, element-wise

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., -2., -3.]), arr.floor());
source

fn ceil(&self) -> Result<Array<N>, ArrayError>

Return the ceil of the input, element-wise

Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![2.01, 4.6, -1.6, -2.2]);
assert_eq!(Array::flat(vec![3., 5., -1., -2.]), arr.ceil());

Implementations on Foreign Types§

source§

impl<N: Numeric> ArrayRounding<N> for Result<Array<N>, ArrayError>

source§

fn round(&self, decimals: &Array<isize>) -> Result<Array<N>, ArrayError>

source§

fn around(&self, decimals: &Array<isize>) -> Result<Array<N>, ArrayError>

source§

fn rint(&self) -> Result<Array<N>, ArrayError>

source§

fn fix(&self) -> Result<Array<N>, ArrayError>

source§

fn trunc(&self) -> Result<Array<N>, ArrayError>

source§

fn floor(&self) -> Result<Array<N>, ArrayError>

source§

fn ceil(&self) -> Result<Array<N>, ArrayError>

Implementors§