pub struct Decimal { /* private fields */ }
Expand description
A Decimal number implemented using the builtin tarantool api.
Availability
This api is not available in all versions of tarantool.
Use tarantool::ffi::has_decimal
to check if it is supported in your
case.
If has_decimal
returns false
, using any function from this module
will result in a panic.
This API is thread-safe unlike the original tarantool decimal API.
Implementations§
source§impl Decimal
impl Decimal
source§impl Decimal
impl Decimal
sourcepub fn floor(self) -> Self
pub fn floor(self) -> Self
Floor a given decimal towards zero to have zero digits after the decimal point.
sourcepub fn round_to(self, scale: u8) -> Option<Self>
pub fn round_to(self, scale: u8) -> Option<Self>
Round a given decimal to have no more than scale
digits after the
decimal point. If scale
if greater than current self.scale()
,
return self
unchanged. Scale must be in range [0..= ffi::DECIMAL_MAX_DIGITS]
. Return None
if scale
if out of bounds.
sourcepub fn floor_to(self, scale: u8) -> Option<Self>
pub fn floor_to(self, scale: u8) -> Option<Self>
Like Decimal::round
but rounds the number towards zero.
sourcepub fn rescale(self, scale: u8) -> Option<Self>
pub fn rescale(self, scale: u8) -> Option<Self>
Set scale of self
to scale
. If scale
< self.scale()
, performs
the equivalent of self.
round
(scale)
. Otherwise appends a
sufficient amount of trailing fractional zeros. Return None
if scale
< 0
or too big.
sourcepub fn sqrt(self) -> Option<Self>
pub fn sqrt(self) -> Option<Self>
Compute square root of self
. Return None
if the result is imaginary
or out of range.
sourcepub fn pow(self, pow: impl Into<Self>) -> Option<Self>
pub fn pow(self, pow: impl Into<Self>) -> Option<Self>
Compute self
raised to the power of pow
. Return None
if the result
is out of range.
Trait Implementations§
source§impl<T: Into<Decimal>> AddAssign<T> for Decimal
impl<T: Into<Decimal>> AddAssign<T> for Decimal
source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+=
operation. Read moresource§impl<'de> Deserialize<'de> for Decimal
impl<'de> Deserialize<'de> for Decimal
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<T: Into<Decimal>> DivAssign<T> for Decimal
impl<T: Into<Decimal>> DivAssign<T> for Decimal
source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/=
operation. Read moresource§impl<L> LuaRead<L> for Decimalwhere
L: AsLua,
impl<L> LuaRead<L> for Decimalwhere
L: AsLua,
source§fn lua_read_at_position(lua: L, index: NonZeroI32) -> ReadResult<Self, L>
fn lua_read_at_position(lua: L, index: NonZeroI32) -> ReadResult<Self, L>
fn n_values_expected() -> i32
fn lua_read_at_maybe_zero_position(
lua: L,
index: i32
) -> Result<Self, (L, WrongType)>where
L: AsLua,
source§impl<T: Into<Decimal>> MulAssign<T> for Decimal
impl<T: Into<Decimal>> MulAssign<T> for Decimal
source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read moresource§impl Ord for Decimal
impl Ord for Decimal
source§impl PartialEq<isize> for Decimal
impl PartialEq<isize> for Decimal
source§impl PartialEq<usize> for Decimal
impl PartialEq<usize> for Decimal
source§impl PartialEq for Decimal
impl PartialEq for Decimal
source§impl PartialOrd for Decimal
impl PartialOrd for Decimal
Cmp
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<L: AsLua> Push<L> for Decimal
impl<L: AsLua> Push<L> for Decimal
source§impl<L: AsLua> PushInto<L> for Decimal
impl<L: AsLua> PushInto<L> for Decimal
source§impl<T: Into<Decimal>> RemAssign<T> for Decimal
impl<T: Into<Decimal>> RemAssign<T> for Decimal
source§fn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%=
operation. Read moresource§impl<T: Into<Decimal>> SubAssign<T> for Decimal
impl<T: Into<Decimal>> SubAssign<T> for Decimal
source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-=
operation. Read more