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
impl Numeric
Sourcepub fn moment(
n: i64,
sum: &Numeric,
squares: &Numeric,
sample: bool,
root: bool,
) -> Result<Numeric, TypeError>
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§impl Numeric
impl Numeric
Sourcepub fn div_trunc(&self, other: &Numeric) -> Result<Numeric, TypeError>
pub fn div_trunc(&self, other: &Numeric) -> Result<Numeric, TypeError>
numeric_div_trunc: the quotient cut to an integer.
Sourcepub fn gcd(&self, other: &Numeric) -> Result<Numeric, TypeError>
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.
Sourcepub fn lcm(&self, other: &Numeric) -> Result<Numeric, TypeError>
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.
Sourcepub fn factorial(n: i64) -> Result<Numeric, TypeError>
pub fn factorial(n: i64) -> Result<Numeric, TypeError>
numeric_fac: the factorial of an integer.
Sourcepub fn scale(&self) -> Option<i32>
pub fn scale(&self) -> Option<i32>
numeric_scale: the display scale, or None for NaN and the infinities.
Sourcepub fn min_scale(&self) -> Option<i32>
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.
Sourcepub fn trim_scale(&self) -> Numeric
pub fn trim_scale(&self) -> Numeric
numeric_trim_scale: the value with the display scale of numeric_min_scale.
Source§impl Numeric
impl Numeric
pub const NAN: Numeric
pub const INFINITY: Numeric
pub const NEGATIVE_INFINITY: Numeric
pub fn sign(&self) -> NumericSign
Sourcepub fn dscale(&self) -> u16
pub fn dscale(&self) -> u16
The number of decimal digits that the output shows after the point.
Sourcepub fn from_decimal(value: i128, scale: u32) -> Numeric
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.
Sourcepub fn to_decimal(&self, scale: u32) -> Option<i128>
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
impl Numeric
Sourcepub fn from_bytes(bytes: &[u8]) -> Numeric
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.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
The bytes of the value in the layout of crate::numeric_layout.
Sourcepub fn from_integer(value: i128) -> Numeric
pub fn from_integer(value: i128) -> Numeric
The value of an integer, with a display scale of 0, as int8_numeric gives it.
Sourcepub fn from_f64(value: f64) -> Numeric
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.
Sourcepub fn to_integer(&self, type_name: &str) -> Result<i128, TypeError>
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.
Sourcepub fn with_typmod(&self, typmod: i32) -> Result<Numeric, TypeError>
pub fn with_typmod(&self, typmod: i32) -> Result<Numeric, TypeError>
The value with typmod applied, as a cast to numeric(p, s) gives it.
Sourcepub fn round(&self, scale: i32) -> Result<Numeric, TypeError>
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.
Sourcepub fn trunc(&self, scale: i32) -> Result<Numeric, TypeError>
pub fn trunc(&self, scale: i32) -> Result<Numeric, TypeError>
numeric_trunc: the digits after scale digits after the point dropped.
Sourcepub fn whole(&self, up: bool) -> Result<Numeric, TypeError>
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.
Sourcepub fn add(&self, other: &Numeric) -> Result<Numeric, TypeError>
pub fn add(&self, other: &Numeric) -> Result<Numeric, TypeError>
numeric_add: the display scale is the larger of the two.
Sourcepub fn mul(&self, other: &Numeric) -> Result<Numeric, TypeError>
pub fn mul(&self, other: &Numeric) -> Result<Numeric, TypeError>
numeric_mul: the display scale is the sum of the two.
Sourcepub fn div(&self, other: &Numeric) -> Result<Numeric, TypeError>
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.