Trait 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§

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()));
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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());
§Errors

may returns ArrayError

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());
§Errors

may returns ArrayError

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());
§Errors

may returns ArrayError

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());
§Errors

may returns ArrayError

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());
§Errors

may returns ArrayError

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

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

Source§

fn round(&self, decimals: &Array<isize>) -> Self

Source§

fn around(&self, decimals: &Array<isize>) -> Self

Source§

fn rint(&self) -> Self

Source§

fn fix(&self) -> Self

Source§

fn trunc(&self) -> Self

Source§

fn floor(&self) -> Self

Source§

fn ceil(&self) -> Self

Implementors§