[][src]Struct bigdecimal::BigDecimal

pub struct BigDecimal { /* fields omitted */ }

A big decimal type.

Methods

impl BigDecimal[src]

pub fn new(digits: BigInt, scale: i64) -> BigDecimal[src]

Creates and initializes a BigDecimal.

pub fn parse_bytes(buf: &[u8], radix: u32) -> Option<BigDecimal>[src]

Creates and initializes a BigDecimal.

Examples

use bigdecimal::{BigDecimal, Zero};

assert_eq!(BigDecimal::parse_bytes(b"0", 10).unwrap(), BigDecimal::zero());
// assert_eq!(BigDecimal::parse_bytes(b"f", 16), BigDecimal::parse_bytes(b"16", 10));

pub fn with_scale(&self, new_scale: i64) -> BigDecimal[src]

Return a new BigDecimal object equivalent to self, with internal scaling set to the number specified. If the new_scale is lower than the current value (indicating a larger power of 10), digits will be dropped (as precision is lower)

pub fn with_prec(&self, prec: u64) -> BigDecimal[src]

Return a new BigDecimal object with precision set to new value

pub fn sign(&self) -> Sign[src]

Return the sign of the BigDecimal as num::bigint::Sign.

Examples

extern crate num_bigint;
extern crate bigdecimal;
use std::str::FromStr;

assert_eq!(bigdecimal::BigDecimal::from_str("-1").unwrap().sign(), num_bigint::Sign::Minus);
assert_eq!(bigdecimal::BigDecimal::from_str("0").unwrap().sign(), num_bigint::Sign::NoSign);
assert_eq!(bigdecimal::BigDecimal::from_str("1").unwrap().sign(), num_bigint::Sign::Plus);

pub fn as_bigint_and_exponent(&self) -> (BigInt, i64)[src]

Return the internal big integer value and an exponent. Note that a positive exponent indicates a negative power of 10.

Examples

extern crate num_bigint;
extern crate bigdecimal;
use std::str::FromStr;

assert_eq!(bigdecimal::BigDecimal::from_str("1.1").unwrap().as_bigint_and_exponent(),
           (num_bigint::BigInt::from_str("11").unwrap(), 1));

pub fn into_bigint_and_exponent(self) -> (BigInt, i64)[src]

Convert into the internal big integer value and an exponent. Note that a positive exponent indicates a negative power of 10.

Examples

extern crate num_bigint;
extern crate bigdecimal;
use std::str::FromStr;

assert_eq!(bigdecimal::BigDecimal::from_str("1.1").unwrap().into_bigint_and_exponent(),
           (num_bigint::BigInt::from_str("11").unwrap(), 1));

pub fn digits(&self) -> u64[src]

Number of digits in the non-scaled integer representation

pub fn abs(&self) -> BigDecimal[src]

Compute the absolute value of number

pub fn double(&self) -> BigDecimal[src]

pub fn half(&self) -> BigDecimal[src]

Divide this efficiently by 2

Note, if this is odd, the precision will increase by 1, regardless of the context's limit.

pub fn square(&self) -> BigDecimal[src]

pub fn cube(&self) -> BigDecimal[src]

pub fn sqrt(&self) -> Option<BigDecimal>[src]

Take the square root of the number

If the value is < 0, None is returned

pub fn cbrt(&self) -> BigDecimal[src]

Take the cube root of the number

pub fn inverse(&self) -> BigDecimal[src]

Compute the reciprical of the number: x-1

pub fn is_integer(&self) -> bool[src]

Return true if this number has zero fractional part (is equal to an integer)

pub fn exp(&self) -> BigDecimal[src]

Evaluate the natural-exponential function ex

Trait Implementations

impl Default for BigDecimal[src]

impl Clone for BigDecimal[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Ord for BigDecimal[src]

fn cmp(&self, other: &BigDecimal) -> Ordering[src]

Complete ordering implementation for BigDecimal

Example

use std::str::FromStr;

let a = bigdecimal::BigDecimal::from_str("-1").unwrap();
let b = bigdecimal::BigDecimal::from_str("1").unwrap();
assert!(a < b);
assert!(b > a);
let c = bigdecimal::BigDecimal::from_str("1").unwrap();
assert!(b >= c);
assert!(c >= b);
let d = bigdecimal::BigDecimal::from_str("10.0").unwrap();
assert!(d > c);
let e = bigdecimal::BigDecimal::from_str(".5").unwrap();
assert!(e < c);

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl From<i64> for BigDecimal[src]

impl From<u64> for BigDecimal[src]

impl From<(BigInt, i64)> for BigDecimal[src]

impl From<BigInt> for BigDecimal[src]

impl From<u8> for BigDecimal[src]

impl From<u16> for BigDecimal[src]

impl From<u32> for BigDecimal[src]

impl From<i8> for BigDecimal[src]

impl From<i16> for BigDecimal[src]

impl From<i32> for BigDecimal[src]

impl From<f32> for BigDecimal[src]

impl From<f64> for BigDecimal[src]

impl Eq for BigDecimal[src]

impl PartialOrd<BigDecimal> for BigDecimal[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq<BigDecimal> for BigDecimal[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl Debug for BigDecimal[src]

impl Display for BigDecimal[src]

impl FromStr for BigDecimal[src]

type Err = ParseBigDecimalError

The associated error which can be returned from parsing.

impl Add<BigDecimal> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a> Add<&'a BigDecimal> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a> Add<BigDecimal> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'b BigDecimal> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the + operator.

impl Add<BigInt> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a> Add<&'a BigInt> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a> Add<BigInt> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a BigInt> for &'b BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the + operator.

impl Sub<BigDecimal> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a> Sub<&'a BigDecimal> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a> Sub<BigDecimal> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'b BigDecimal> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the - operator.

impl Sub<BigInt> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a> Sub<&'a BigInt> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a> Sub<BigInt> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a BigInt> for &'b BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the - operator.

impl Mul<BigDecimal> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a> Mul<&'a BigDecimal> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a> Mul<BigDecimal> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'b BigDecimal> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the * operator.

impl Mul<BigInt> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a> Mul<&'a BigInt> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a> Mul<BigInt> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a BigInt> for &'b BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a> Div<f32> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for f32[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for f32[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<f64> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for f64[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for f64[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i8> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i8> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for i8[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for i8[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i16> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i16> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for i16[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for i16[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i32> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i32> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for i32[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for i32[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i64> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i64> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for i64[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for i64[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<u8> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for u8[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for u8[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<u16> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for u16[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for u16[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<u32> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for u32[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for u32[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<u64> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for u64[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for u64[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<&'a BigDecimal> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<BigDecimal> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a, 'b> Div<&'b BigDecimal> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the / operator.

impl Rem<BigDecimal> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the % operator.

impl<'a> Rem<&'a BigDecimal> for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the % operator.

impl<'a> Rem<BigDecimal> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the % operator.

impl<'a, 'b> Rem<&'b BigDecimal> for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the % operator.

impl Neg for BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a> Neg for &'a BigDecimal[src]

type Output = BigDecimal

The resulting type after applying the - operator.

impl AddAssign<BigDecimal> for BigDecimal[src]

impl<'a> AddAssign<&'a BigDecimal> for BigDecimal[src]

impl<'a> AddAssign<BigInt> for BigDecimal[src]

impl<'a> AddAssign<&'a BigInt> for BigDecimal[src]

impl SubAssign<BigDecimal> for BigDecimal[src]

impl<'a> SubAssign<&'a BigDecimal> for BigDecimal[src]

impl<'a> SubAssign<BigInt> for BigDecimal[src]

impl<'a> SubAssign<&'a BigInt> for BigDecimal[src]

impl MulAssign<BigDecimal> for BigDecimal[src]

impl<'a> MulAssign<&'a BigDecimal> for BigDecimal[src]

impl Hash for BigDecimal[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Sum<BigDecimal> for BigDecimal[src]

impl<'a> Sum<&'a BigDecimal> for BigDecimal[src]

impl ToBigInt for BigDecimal[src]

impl ToPrimitive for BigDecimal[src]

fn to_isize(&self) -> Option<isize>[src]

Converts the value of self to an isize.

fn to_i8(&self) -> Option<i8>[src]

Converts the value of self to an i8.

fn to_i16(&self) -> Option<i16>[src]

Converts the value of self to an i16.

fn to_i32(&self) -> Option<i32>[src]

Converts the value of self to an i32.

fn to_i128(&self) -> Option<i128>[src]

Converts the value of self to an i128. Read more

fn to_usize(&self) -> Option<usize>[src]

Converts the value of self to a usize.

fn to_u8(&self) -> Option<u8>[src]

Converts the value of self to an u8.

fn to_u16(&self) -> Option<u16>[src]

Converts the value of self to an u16.

fn to_u32(&self) -> Option<u32>[src]

Converts the value of self to an u32.

fn to_u128(&self) -> Option<u128>[src]

Converts the value of self to an u128. Read more

fn to_f32(&self) -> Option<f32>[src]

Converts the value of self to an f32.

impl FromPrimitive for BigDecimal[src]

fn from_isize(n: isize) -> Option<Self>[src]

Convert an isize to return an optional value of this type. If the value cannot be represented by this value, then None is returned. Read more

fn from_i8(n: i8) -> Option<Self>[src]

Convert an i8 to return an optional value of this type. If the type cannot be represented by this value, then None is returned. Read more

fn from_i16(n: i16) -> Option<Self>[src]

Convert an i16 to return an optional value of this type. If the type cannot be represented by this value, then None is returned. Read more

fn from_i32(n: i32) -> Option<Self>[src]

Convert an i32 to return an optional value of this type. If the type cannot be represented by this value, then None is returned. Read more

fn from_i128(n: i128) -> Option<Self>[src]

Convert an i128 to return an optional value of this type. If the type cannot be represented by this value, then None is returned. Read more

fn from_usize(n: usize) -> Option<Self>[src]

Convert a usize to return an optional value of this type. If the type cannot be represented by this value, then None is returned. Read more

fn from_u8(n: u8) -> Option<Self>[src]

Convert an u8 to return an optional value of this type. If the type cannot be represented by this value, then None is returned. Read more

fn from_u16(n: u16) -> Option<Self>[src]

Convert an u16 to return an optional value of this type. If the type cannot be represented by this value, then None is returned. Read more

fn from_u32(n: u32) -> Option<Self>[src]

Convert an u32 to return an optional value of this type. If the type cannot be represented by this value, then None is returned. Read more

fn from_u128(n: u128) -> Option<Self>[src]

Convert an u128 to return an optional value of this type. If the type cannot be represented by this value, then None is returned. Read more

impl Num for BigDecimal[src]

type FromStrRadixErr = ParseBigDecimalError

fn from_str_radix(
    s: &str,
    radix: u32
) -> Result<BigDecimal, ParseBigDecimalError>
[src]

Creates and initializes a BigDecimal.

impl Zero for BigDecimal[src]

fn set_zero(&mut self)[src]

Sets self to the additive identity element of Self, 0.

impl One for BigDecimal[src]

fn set_one(&mut self)[src]

Sets self to the multiplicative identity element of Self, 1.

fn is_one(&self) -> bool where
    Self: PartialEq<Self>, 
[src]

Returns true if self is equal to the multiplicative identity. Read more

impl Signed for BigDecimal[src]

Auto Trait Implementations

impl Send for BigDecimal

impl Sync for BigDecimal

Blanket Implementations

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
    T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, 
[src]

impl<T> NumRef for T where
    T: Num + NumOps<&'r T, T>, 
[src]

impl<T, Base> RefNum<Base> for T where
    T: NumOps<Base, Base> + NumOps<&'r Base, Base>, 
[src]