[−]Struct sqlx::types::BigDecimal
A big decimal type.
Methods
impl BigDecimal
pub fn new(digits: BigInt, scale: i64) -> BigDecimal
Creates and initializes a BigDecimal
.
pub fn parse_bytes(buf: &[u8], radix: u32) -> Option<BigDecimal>
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
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
Return a new BigDecimal object with precision set to new value
pub fn sign(&self) -> Sign
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)
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)
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
Number of digits in the non-scaled integer representation
pub fn abs(&self) -> BigDecimal
Compute the absolute value of number
pub fn double(&self) -> BigDecimal
pub fn half(&self) -> BigDecimal
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
pub fn cube(&self) -> BigDecimal
pub fn sqrt(&self) -> Option<BigDecimal>
Take the square root of the number
If the value is < 0, None is returned
pub fn cbrt(&self) -> BigDecimal
Take the cube root of the number
pub fn inverse(&self) -> BigDecimal
Compute the reciprical of the number: x-1
pub fn is_integer(&self) -> bool
Return true if this number has zero fractional part (is equal to an integer)
pub fn exp(&self) -> BigDecimal
Evaluate the natural-exponential function ex
Trait Implementations
impl<'a> Add<&'a BigDecimal> for BigDecimal
type Output = BigDecimal
The resulting type after applying the +
operator.
fn add(self, rhs: &'a BigDecimal) -> BigDecimal
impl<'a> Add<&'a BigInt> for BigDecimal
type Output = BigDecimal
The resulting type after applying the +
operator.
fn add(self, rhs: &BigInt) -> BigDecimal
impl<'a, 'b> Add<&'a BigInt> for &'b BigDecimal
type Output = BigDecimal
The resulting type after applying the +
operator.
fn add(self, rhs: &BigInt) -> BigDecimal
impl<'a, 'b> Add<&'b BigDecimal> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the +
operator.
fn add(self, rhs: &BigDecimal) -> BigDecimal
impl Add<BigDecimal> for BigDecimal
type Output = BigDecimal
The resulting type after applying the +
operator.
fn add(self, rhs: BigDecimal) -> BigDecimal
impl<'a> Add<BigDecimal> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the +
operator.
fn add(self, rhs: BigDecimal) -> BigDecimal
impl<'a> Add<BigInt> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the +
operator.
fn add(self, rhs: BigInt) -> BigDecimal
impl Add<BigInt> for BigDecimal
type Output = BigDecimal
The resulting type after applying the +
operator.
fn add(self, rhs: BigInt) -> BigDecimal
impl<'a> AddAssign<&'a BigDecimal> for BigDecimal
fn add_assign(&mut self, rhs: &BigDecimal)
impl<'a> AddAssign<&'a BigInt> for BigDecimal
fn add_assign(&mut self, rhs: &BigInt)
impl AddAssign<BigDecimal> for BigDecimal
fn add_assign(&mut self, other: BigDecimal)
impl<'a> AddAssign<BigInt> for BigDecimal
fn add_assign(&mut self, rhs: BigInt)
impl Clone for BigDecimal
fn clone(&self) -> BigDecimal
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for BigDecimal
impl<'_> Decode<'_, MySql> for BigDecimal
[src]
fn decode(value: MySqlValue) -> Result<BigDecimal, Error>
[src]
impl<'_> Decode<'_, Postgres> for BigDecimal
[src]
impl Default for BigDecimal
fn default() -> BigDecimal
impl Display for BigDecimal
impl<'a> Div<&'a BigDecimal> for BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, other: &'a BigDecimal) -> BigDecimal
impl<'a, 'b> Div<&'b BigDecimal> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, other: &BigDecimal) -> BigDecimal
impl Div<BigDecimal> for BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, other: BigDecimal) -> BigDecimal
impl<'a> Div<BigDecimal> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, other: BigDecimal) -> BigDecimal
impl<'a> Div<f32> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: f32) -> <&'a BigDecimal as Div<f32>>::Output
impl<'a> Div<f64> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: f64) -> <&'a BigDecimal as Div<f64>>::Output
impl<'a> Div<i16> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: i16) -> <&'a BigDecimal as Div<i16>>::Output
impl<'a> Div<i16> for BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: i16) -> <BigDecimal as Div<i16>>::Output
impl<'a> Div<i32> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: i32) -> <&'a BigDecimal as Div<i32>>::Output
impl<'a> Div<i32> for BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: i32) -> <BigDecimal as Div<i32>>::Output
impl<'a> Div<i64> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: i64) -> <&'a BigDecimal as Div<i64>>::Output
impl<'a> Div<i64> for BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: i64) -> <BigDecimal as Div<i64>>::Output
impl<'a> Div<i8> for BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: i8) -> <BigDecimal as Div<i8>>::Output
impl<'a> Div<i8> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: i8) -> <&'a BigDecimal as Div<i8>>::Output
impl<'a> Div<u16> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: u16) -> <&'a BigDecimal as Div<u16>>::Output
impl<'a> Div<u32> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: u32) -> <&'a BigDecimal as Div<u32>>::Output
impl<'a> Div<u64> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: u64) -> <&'a BigDecimal as Div<u64>>::Output
impl<'a> Div<u8> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the /
operator.
fn div(self, den: u8) -> <&'a BigDecimal as Div<u8>>::Output
impl Encode<MySql> for BigDecimal
[src]
fn encode(&self, buf: &mut Vec<u8>)
[src]
fn size_hint(&self) -> usize
[src]
fn encode_nullable(&self, buf: &mut <DB as Database>::RawBuffer) -> IsNull
[src]
impl Encode<Postgres> for BigDecimal
[src]
Panics
If this BigDecimal
cannot be represented by [PgNumeric].
fn encode(&self, buf: &mut PgRawBuffer)
[src]
fn size_hint(&self) -> usize
[src]
fn encode_nullable(&self, buf: &mut <DB as Database>::RawBuffer) -> IsNull
[src]
impl Eq for BigDecimal
impl From<(BigInt, i64)> for BigDecimal
impl From<BigInt> for BigDecimal
fn from(int_val: BigInt) -> BigDecimal
impl From<f32> for BigDecimal
fn from(n: f32) -> BigDecimal
impl From<f64> for BigDecimal
fn from(n: f64) -> BigDecimal
impl From<i16> for BigDecimal
fn from(n: i16) -> BigDecimal
impl From<i32> for BigDecimal
fn from(n: i32) -> BigDecimal
impl From<i64> for BigDecimal
fn from(n: i64) -> BigDecimal
impl From<i8> for BigDecimal
fn from(n: i8) -> BigDecimal
impl From<u16> for BigDecimal
fn from(n: u16) -> BigDecimal
impl From<u32> for BigDecimal
fn from(n: u32) -> BigDecimal
impl From<u64> for BigDecimal
fn from(n: u64) -> BigDecimal
impl From<u8> for BigDecimal
fn from(n: u8) -> BigDecimal
impl FromPrimitive for BigDecimal
fn from_i64(n: i64) -> Option<BigDecimal>
fn from_u64(n: u64) -> Option<BigDecimal>
fn from_f32(n: f32) -> Option<BigDecimal>
fn from_f64(n: f64) -> Option<BigDecimal>
fn from_isize(n: isize) -> Option<Self>
[src]
fn from_i8(n: i8) -> Option<Self>
[src]
fn from_i16(n: i16) -> Option<Self>
[src]
fn from_i32(n: i32) -> Option<Self>
[src]
fn from_i128(n: i128) -> Option<Self>
[src]
fn from_usize(n: usize) -> Option<Self>
[src]
fn from_u8(n: u8) -> Option<Self>
[src]
fn from_u16(n: u16) -> Option<Self>
[src]
fn from_u32(n: u32) -> Option<Self>
[src]
fn from_u128(n: u128) -> Option<Self>
[src]
impl FromStr for BigDecimal
type Err = ParseBigDecimalError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<BigDecimal, ParseBigDecimalError>
impl Hash for BigDecimal
fn hash<H>(&self, state: &mut H) where
H: Hasher,
H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> Mul<&'a BigDecimal> for BigDecimal
type Output = BigDecimal
The resulting type after applying the *
operator.
fn mul(self, rhs: &'a BigDecimal) -> BigDecimal
impl<'a> Mul<&'a BigInt> for BigDecimal
type Output = BigDecimal
The resulting type after applying the *
operator.
fn mul(self, rhs: &BigInt) -> BigDecimal
impl<'a, 'b> Mul<&'a BigInt> for &'b BigDecimal
type Output = BigDecimal
The resulting type after applying the *
operator.
fn mul(self, rhs: &BigInt) -> BigDecimal
impl<'a, 'b> Mul<&'b BigDecimal> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the *
operator.
fn mul(self, rhs: &BigDecimal) -> BigDecimal
impl<'a> Mul<BigDecimal> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the *
operator.
fn mul(self, rhs: BigDecimal) -> BigDecimal
impl Mul<BigDecimal> for BigDecimal
type Output = BigDecimal
The resulting type after applying the *
operator.
fn mul(self, rhs: BigDecimal) -> BigDecimal
impl Mul<BigInt> for BigDecimal
type Output = BigDecimal
The resulting type after applying the *
operator.
fn mul(self, rhs: BigInt) -> BigDecimal
impl<'a> Mul<BigInt> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the *
operator.
fn mul(self, rhs: BigInt) -> BigDecimal
impl<'a> MulAssign<&'a BigDecimal> for BigDecimal
fn mul_assign(&mut self, rhs: &BigDecimal)
impl MulAssign<BigDecimal> for BigDecimal
fn mul_assign(&mut self, other: BigDecimal)
impl<'a> Neg for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the -
operator.
fn neg(self) -> BigDecimal
impl Neg for BigDecimal
type Output = BigDecimal
The resulting type after applying the -
operator.
fn neg(self) -> BigDecimal
impl Num for BigDecimal
type FromStrRadixErr = ParseBigDecimalError
fn from_str_radix(
s: &str,
radix: u32
) -> Result<BigDecimal, ParseBigDecimalError>
s: &str,
radix: u32
) -> Result<BigDecimal, ParseBigDecimalError>
Creates and initializes a BigDecimal.
impl One for BigDecimal
fn one() -> BigDecimal
fn set_one(&mut self)
[src]
fn is_one(&self) -> bool where
Self: PartialEq<Self>,
[src]
Self: PartialEq<Self>,
impl Ord for BigDecimal
fn cmp(&self, other: &BigDecimal) -> Ordering
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);
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<BigDecimal> for BigDecimal
impl PartialOrd<BigDecimal> for BigDecimal
fn partial_cmp(&self, other: &BigDecimal) -> Option<Ordering>
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> Rem<&'a BigDecimal> for BigDecimal
type Output = BigDecimal
The resulting type after applying the %
operator.
fn rem(self, other: &BigDecimal) -> BigDecimal
impl<'a, 'b> Rem<&'b BigDecimal> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the %
operator.
fn rem(self, other: &BigDecimal) -> BigDecimal
impl Rem<BigDecimal> for BigDecimal
type Output = BigDecimal
The resulting type after applying the %
operator.
fn rem(self, other: BigDecimal) -> BigDecimal
impl<'a> Rem<BigDecimal> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the %
operator.
fn rem(self, other: BigDecimal) -> BigDecimal
impl Signed for BigDecimal
fn abs(&self) -> BigDecimal
fn abs_sub(&self, other: &BigDecimal) -> BigDecimal
fn signum(&self) -> BigDecimal
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
impl StructuralEq for BigDecimal
impl<'a> Sub<&'a BigDecimal> for BigDecimal
type Output = BigDecimal
The resulting type after applying the -
operator.
fn sub(self, rhs: &BigDecimal) -> BigDecimal
impl<'a> Sub<&'a BigInt> for BigDecimal
type Output = BigDecimal
The resulting type after applying the -
operator.
fn sub(self, rhs: &BigInt) -> BigDecimal
impl<'a, 'b> Sub<&'a BigInt> for &'b BigDecimal
type Output = BigDecimal
The resulting type after applying the -
operator.
fn sub(self, rhs: &BigInt) -> BigDecimal
impl<'a, 'b> Sub<&'b BigDecimal> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the -
operator.
fn sub(self, rhs: &BigDecimal) -> BigDecimal
impl Sub<BigDecimal> for BigDecimal
type Output = BigDecimal
The resulting type after applying the -
operator.
fn sub(self, rhs: BigDecimal) -> BigDecimal
impl<'a> Sub<BigDecimal> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the -
operator.
fn sub(self, rhs: BigDecimal) -> BigDecimal
impl<'a> Sub<BigInt> for &'a BigDecimal
type Output = BigDecimal
The resulting type after applying the -
operator.
fn sub(self, rhs: BigInt) -> BigDecimal
impl Sub<BigInt> for BigDecimal
type Output = BigDecimal
The resulting type after applying the -
operator.
fn sub(self, rhs: BigInt) -> BigDecimal
impl<'a> SubAssign<&'a BigDecimal> for BigDecimal
fn sub_assign(&mut self, rhs: &BigDecimal)
impl<'a> SubAssign<&'a BigInt> for BigDecimal
fn sub_assign(&mut self, rhs: &BigInt)
impl SubAssign<BigDecimal> for BigDecimal
fn sub_assign(&mut self, other: BigDecimal)
impl<'a> SubAssign<BigInt> for BigDecimal
fn sub_assign(&mut self, rhs: BigInt)
impl<'a> Sum<&'a BigDecimal> for BigDecimal
fn sum<I>(iter: I) -> BigDecimal where
I: Iterator<Item = &'a BigDecimal>,
I: Iterator<Item = &'a BigDecimal>,
impl Sum<BigDecimal> for BigDecimal
fn sum<I>(iter: I) -> BigDecimal where
I: Iterator<Item = BigDecimal>,
I: Iterator<Item = BigDecimal>,
impl ToBigInt for BigDecimal
impl ToPrimitive for BigDecimal
fn to_i64(&self) -> Option<i64>
fn to_u64(&self) -> Option<u64>
fn to_f64(&self) -> Option<f64>
fn to_isize(&self) -> Option<isize>
[src]
fn to_i8(&self) -> Option<i8>
[src]
fn to_i16(&self) -> Option<i16>
[src]
fn to_i32(&self) -> Option<i32>
[src]
fn to_i128(&self) -> Option<i128>
[src]
fn to_usize(&self) -> Option<usize>
[src]
fn to_u8(&self) -> Option<u8>
[src]
fn to_u16(&self) -> Option<u16>
[src]
fn to_u32(&self) -> Option<u32>
[src]
fn to_u128(&self) -> Option<u128>
[src]
fn to_f32(&self) -> Option<f32>
[src]
impl TryFrom<PgNumeric> for BigDecimal
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(numeric: PgNumeric) -> Result<BigDecimal, Error>
[src]
impl Type<MySql> for BigDecimal
[src]
fn type_info() -> MySqlTypeInfo
[src]
impl Type<Postgres> for BigDecimal
[src]
fn type_info() -> PgTypeInfo
[src]
impl Zero for BigDecimal
Auto Trait Implementations
impl RefUnwindSafe for BigDecimal
impl Send for BigDecimal
impl Sync for BigDecimal
impl Unpin for BigDecimal
impl UnwindSafe for BigDecimal
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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]
T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,
impl<T> NumRef for T where
T: Num + for<'r> NumOps<&'r T, T>,
[src]
T: Num + for<'r> NumOps<&'r T, T>,
impl<T, Base> RefNum<Base> for T where
T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,
[src]
T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> Sealed<T> for T where
T: ?Sized,
T: ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,