Skip to main content

Numeric

Struct Numeric 

Source
pub struct Numeric { /* private fields */ }
Expand description

A numeric value as PostgreSQL stores it. The digits have no zero at either end. A zero has no digits, a weight of 0 and a positive sign, and it keeps its display scale. A special value has only its sign.

Implementations§

Source§

impl Numeric

Source

pub fn sqrt(&self) -> Result<Numeric, TypeError>

numeric_sqrt.

Source

pub fn moment( n: i64, sum: &Numeric, squares: &Numeric, sample: bool, root: bool, ) -> Result<Numeric, TypeError>

The end of numeric_stddev_internal for finite values: the variance or, when root is set, the standard deviation of n values with the sum sum and the sum of squares squares. The variance of a sample divides by n * (n - 1) and the variance of the population by n * n. The caller makes sure that n is above 0, and above 1 for a sample.

Source

pub fn exp(&self) -> Result<Numeric, TypeError>

numeric_exp.

Source

pub fn ln(&self) -> Result<Numeric, TypeError>

numeric_ln.

Source

pub fn log(&self, num: &Numeric) -> Result<Numeric, TypeError>

numeric_log: the logarithm of num in the base self.

Source

pub fn power(&self, exp: &Numeric) -> Result<Numeric, TypeError>

numeric_power: the rules of POSIX pow for NaN and the infinities.

Source§

impl Numeric

Source

pub fn div_trunc(&self, other: &Numeric) -> Result<Numeric, TypeError>

numeric_div_trunc: the quotient cut to an integer.

Source

pub fn gcd(&self, other: &Numeric) -> Result<Numeric, TypeError>

numeric_gcd: the greatest common divisor, with the larger of the two display scales. NaN and the infinities give NaN.

Source

pub fn lcm(&self, other: &Numeric) -> Result<Numeric, TypeError>

numeric_lcm: the least common multiple, which is zero when one of the two is zero.

Source

pub fn factorial(n: i64) -> Result<Numeric, TypeError>

numeric_fac: the factorial of an integer.

Source

pub fn scale(&self) -> Option<i32>

numeric_scale: the display scale, or None for NaN and the infinities.

Source

pub fn min_scale(&self) -> Option<i32>

numeric_min_scale: the fewest digits after the point that hold the value, or None for NaN and the infinities.

Source

pub fn trim_scale(&self) -> Numeric

numeric_trim_scale: the value with the display scale of numeric_min_scale.

Source

pub fn width_bucket( &self, low: &Numeric, high: &Numeric, count: i32, ) -> Result<i32, TypeError>

width_bucket_numeric: the bucket of self among count buckets of the same width from low to high.

Source§

impl Numeric

Source

pub fn random( prng: &mut Prng, rmin: &Numeric, rmax: &Numeric, ) -> Result<Numeric, TypeError>

random_numeric: a value from rmin to rmax with the larger of the two display scales, from the generator prng.

Source§

impl Numeric

Source

pub const NAN: Numeric

Source

pub const INFINITY: Numeric

Source

pub const NEGATIVE_INFINITY: Numeric

Source

pub fn sign(&self) -> NumericSign

Source

pub fn weight(&self) -> i16

The power of 10000 of the first digit.

Source

pub fn dscale(&self) -> u16

The number of decimal digits that the output shows after the point.

Source

pub fn digits(&self) -> &[i16]

The base-10000 digits, the most significant first.

Source

pub fn from_decimal(value: i128, scale: u32) -> Numeric

The value value / 10^scale, with scale as its display scale, as a cast from a numeric(p, s) column of the engine gives it.

Source

pub fn to_decimal(&self, scale: u32) -> Option<i128>

The value as an integer count of 10^-scale, rounded half away from zero as round_var rounds. None for a special value or a value that does not fit in an i128.

Source§

impl Numeric

Source

pub fn from_bytes(bytes: &[u8]) -> Numeric

The value of bytes in the layout of crate::numeric_layout, which is how a vector holds a value of the type NUMERIC.

Source

pub fn to_bytes(&self) -> Vec<u8> ⓘ

The bytes of the value in the layout of crate::numeric_layout.

Source

pub fn from_integer(value: i128) -> Numeric

The value of an integer, with a display scale of 0, as int8_numeric gives it.

Source

pub fn from_f64(value: f64) -> Numeric

float8_numeric: the value of the double printed with 15 significant digits, so that 0.1::float8::numeric is 0.1.

Source

pub fn to_f64(&self) -> f64

numeric_float8: the double nearest to the text of the value.

Source

pub fn to_integer(&self, type_name: &str) -> Result<i128, TypeError>

The value rounded half away from zero to an integer, as the casts to the integer types round. The error names the type, as numeric_int4 and numeric_int8 do.

Source

pub fn with_typmod(&self, typmod: i32) -> Result<Numeric, TypeError>

The value with typmod applied, as a cast to numeric(p, s) gives it.

Source

pub fn round(&self, scale: i32) -> Result<Numeric, TypeError>

numeric_round: half away from zero to scale digits after the point, or before it when the scale is negative.

Source

pub fn trunc(&self, scale: i32) -> Result<Numeric, TypeError>

numeric_trunc: the digits after scale digits after the point dropped.

Source

pub fn whole(&self, up: bool) -> Result<Numeric, TypeError>

numeric_ceil when up and numeric_floor when not: the nearest whole number on that side.

Source

pub fn abs(&self) -> Numeric

numeric_abs.

Source

pub fn negate(&self) -> Numeric

numeric_uminus.

Source

pub fn add(&self, other: &Numeric) -> Result<Numeric, TypeError>

numeric_add: the display scale is the larger of the two.

Source

pub fn sub(&self, other: &Numeric) -> Result<Numeric, TypeError>

numeric_sub.

Source

pub fn mul(&self, other: &Numeric) -> Result<Numeric, TypeError>

numeric_mul: the display scale is the sum of the two.

Source

pub fn div(&self, other: &Numeric) -> Result<Numeric, TypeError>

numeric_div: the result scale is the one select_div_scale picks, and the last digit is rounded half away from zero.

Source

pub fn modulo(&self, other: &Numeric) -> Result<Numeric, TypeError>

numeric_mod: the remainder of the quotient cut to an integer, with the sign of self.

Source

pub fn compare(&self, other: &Numeric) -> Ordering

cmp_numerics: NaN is equal to itself and above every other value, and the display scale does not count.

Trait Implementations§

Source§

impl Clone for Numeric

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Numeric

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Numeric

Source§

impl PartialEq for Numeric

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Numeric

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.