Struct tidb_query_datatype::codec::mysql::decimal::Decimal [−][src]
Decimal
represents a decimal value.
Fields
int_cnt: u8
The number of decimal digits before the point.
frac_cnt: u8
The number of decimal digits after the point.
result_frac_cnt: u8
The number of calculated or printed result fraction digits.
negative: bool
word_buf: [u32; 9]
An array of u32 words. A word is an u32 value can hold 9 digits.(0 <= word < wordBase)
Implementations
impl Decimal
[src][−]
pub fn abs(self) -> Res<Decimal>
[src][−]
abs the Decimal into a new Decimal.
pub fn ceil(&self) -> Res<Decimal>
[src][−]
ceil the Decimal into a new Decimal.
pub fn floor(&self) -> Res<Decimal>
[src][−]
floor the Decimal into a new Decimal.
fn new(int_cnt: u8, frac_cnt: u8, negative: bool) -> Decimal
[src][−]
create a new decimal for internal usage.
pub fn is_negative(&self) -> bool
[src]
pub fn zero() -> Decimal
[src][−]
Creates a new decimal which is zero.
fn remove_leading_zeroes(&self, prec: u8) -> (usize, u8)
[src][−]
Given a precision count ‘prec’, get:
- the index of first non-zero word in self.word_buf to hold the leading ‘prec’ number of digits
- the number of remained digits if we remove all leading zeros for the leading ‘prec’ number of digits
fn prepare_buf(&self) -> (Vec<u8>, usize, u8, u8, u8)
[src][−]
Prepare a buf for string output.
pub fn prec_and_frac(&self) -> (u8, u8)
[src][−]
Get the least precision and fraction count to encode this decimal completely.
fn digit_bounds(&self) -> (u8, u8)
[src][−]
digit_bounds
returns bounds of decimal digits in the number.
fn do_mini_left_shift(self, shift: u8, beg: u8, end: u8) -> Decimal
[src][−]
do_mini_left_shift
does left shift for alignment of data in buffer.
Result fitting in the buffer should be garanted. ‘shift’ have to be from 1 to DIGITS_PER_WORD - 1 (inclusive)
fn do_mini_right_shift(self, shift: u8, beg: u8, end: u8) -> Decimal
[src][−]
do_mini_right_shift
does right shift for alignment of data in buffer.
Result fitting in the buffer should be garanted. ‘shift’ have to be from 1 to DIGITS_PER_WORD - 1 (inclusive)
pub fn convert_to(
self,
ctx: &mut EvalContext,
flen: u8,
decimal: u8
) -> Result<Decimal>
[src][−]
self,
ctx: &mut EvalContext,
flen: u8,
decimal: u8
) -> Result<Decimal>
convert_to(ProduceDecWithSpecifiedTp in tidb)
produces a new decimal according to flen
and decimal
.
pub fn round(self, frac: i8, round_mode: RoundMode) -> Res<Decimal>
[src][−]
Round rounds the decimal to “frac” digits.
NOTES scale can be negative ! one TRUNCATED error (line XXX below) isn’t treated very logical :(
fn round_with_word_buf_len(
self,
frac: i8,
word_buf_len: u8,
round_mode: RoundMode
) -> Res<Decimal>
[src]
self,
frac: i8,
word_buf_len: u8,
round_mode: RoundMode
) -> Res<Decimal>
fn handle_incr(
res: Res<Decimal>,
int_word_cnt: u8,
frac_words_to: i8,
frac: i8,
frac_word_cnt: u8,
word_buf_len: u8,
round_mode: RoundMode
) -> Res<Decimal>
[src]
res: Res<Decimal>,
int_word_cnt: u8,
frac_words_to: i8,
frac: i8,
frac_word_cnt: u8,
word_buf_len: u8,
round_mode: RoundMode
) -> Res<Decimal>
fn handle_carry(
dec: Res<Decimal>,
to_idx: usize,
frac: i8,
frac_word_to: i8,
int_word_cnt: u8,
word_buf_len: u8
) -> Res<Decimal>
[src]
dec: Res<Decimal>,
to_idx: usize,
frac: i8,
frac_word_to: i8,
int_word_cnt: u8,
word_buf_len: u8
) -> Res<Decimal>
pub fn shift(self, shift: isize) -> Res<Decimal>
[src][−]
shift
shifts decimal digits in given number (with rounding if it need),
shift > 0 means shift to left shift, shift < 0 means right shift.
In fact it is multiplying on 10^shift.
fn shift_with_word_buf_len(self, shift: isize, word_buf_len: u8) -> Res<Decimal>
[src]
pub fn as_i64(&self) -> Res<i64>
[src][−]
as_i64
returns int part of the decimal.
pub fn as_i64_with_ctx(&self, ctx: &mut EvalContext) -> Result<i64>
[src][−]
as_i64_with_ctx
returns int part of the decimal.
pub fn as_u64(&self) -> Res<u64>
[src][−]
as_u64
returns int part of the decimal
pub fn from_f64(val: f64) -> Result<Decimal>
[src]
pub fn from_bytes(s: &[u8]) -> Result<Res<Decimal>>
[src][−]
Returns a Decimal
from a given bytes slice
Notes
An error will be returned if the given input is as follows:
- empty string
- string which cannot be converted to decimal
fn from_bytes_with_word_buf(s: &[u8], word_buf_len: u8) -> Result<Res<Decimal>>
[src][−]
Returns a Decimal
from a given bytes slice buffer and specified buffer length
Notes
An error will be returned if the given input is as follows:
- an empty string
- a string which cannot be converted to decimal
pub fn approximate_encoded_size(&self) -> usize
[src][−]
Get the approximate needed capacity to encode this decimal.
see also encode_decimal
.
fn div(&self, rhs: &Decimal, frac_incr: u8) -> Option<Res<Decimal>>
[src]
pub fn is_zero(&self) -> bool
[src]
Trait Implementations
impl<'a, 'b> Add<&'a Decimal> for &'b Decimal
[src][+]
impl AsMySQLBool for Decimal
[src][+]
impl Clone for Decimal
[src][+]
impl ConvertTo<Decimal> for i64
[src][+]
impl ConvertTo<Decimal> for u64
[src][+]
impl ConvertTo<Decimal> for Time
[src][+]
impl ConvertTo<Decimal> for f64
[src][+]
impl ConvertTo<Decimal> for Real
[src][+]
impl ConvertTo<Decimal> for &[u8]
[src][+]
impl ConvertTo<Decimal> for Cow<'_, [u8]>
[src][+]
impl ConvertTo<Decimal> for Bytes
[src][+]
impl ConvertTo<Decimal> for Json
[src][+]
impl<'a> ConvertTo<Decimal> for JsonRef<'a>
[src][+]
impl ConvertTo<Decimal> for Duration
[src][+]
impl ConvertTo<Json> for Decimal
[src][+]
impl ConvertTo<f64> for Decimal
[src][+]
impl Copy for Decimal
[src]
impl Debug for Decimal
[src][+]
impl Display for Decimal
[src][+]
impl<'a, 'b> Div<&'a Decimal> for &'b Decimal
[src][+]
impl Eq for Decimal
[src]
impl Evaluable for Decimal
[src][+]
impl EvaluableRet for Decimal
[src][+]
impl From<Decimal> for ScalarValue
[src][+]
impl From<Decimal> for Datum
[src][+]
impl From<i16> for Decimal
[src][+]
impl From<i32> for Decimal
[src][+]
impl From<i64> for Decimal
[src][+]
impl From<i8> for Decimal
[src][+]
impl From<isize> for Decimal
[src][+]
impl From<u16> for Decimal
[src][+]
impl From<u32> for Decimal
[src][+]
impl From<u64> for Decimal
[src][+]
impl From<u8> for Decimal
[src][+]
impl From<usize> for Decimal
[src][+]
impl FromStr for Decimal
[src][+]
impl Hash for Decimal
[src][+]
impl<'a, 'b> Mul<&'a Decimal> for &'b Decimal
[src][+]
impl Neg for Decimal
[src][+]
impl Ord for Decimal
[src][+]
impl PartialEq<Decimal> for Decimal
[src][+]
impl PartialOrd<Decimal> for Decimal
[src][+]
impl<'a> RawDatumDecoder<Decimal> for &'a [u8]
[src][+]
impl<'a, 'b> Rem<&'a Decimal> for &'b Decimal
[src][+]
impl Rem<Decimal> for Decimal
[src][+]
impl<'a, 'b> Sub<&'a Decimal> for &'b Decimal
[src][+]
impl ToInt for Decimal
[src][+]
impl ToString for Decimal
[src][+]
impl VectorValueExt<Decimal> for VectorValue
[src][+]
Auto Trait Implementations
impl RefUnwindSafe for Decimal
impl Send for Decimal
impl Sync for Decimal
impl Unpin for Decimal
impl UnwindSafe for Decimal
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,
impl<V, W> ConvertFrom<W> for V where
W: ConvertTo<V>,
[src][+]
W: ConvertTo<V>,
impl<T> ConvertTo<NotNan<f64>> for T where
T: ConvertTo<f64> + EvaluableRet,
[src][+]
T: ConvertTo<f64> + EvaluableRet,
impl<T> ConvertTo<String> for T where
T: ToString + EvaluableRet,
[src][+]
T: ToString + EvaluableRet,
impl<T> ConvertTo<Vec<u8, Global>> for T where
T: ToString + EvaluableRet,
[src][+]
T: ToString + EvaluableRet,
impl<T> ConvertTo<i64> for T where
T: ToInt,
[src][+]
T: ToInt,
impl<T> ConvertTo<u64> for T where
T: ToInt,
[src][+]
T: ToInt,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src][+]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
impl<T> From<T> for T
[src][+]
impl<T> Instrument for T
[src][+]
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<T> Pointable for T
[src][+]
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> Sealed<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> SendSyncUnwindSafe for T where
T: Send + Sync + UnwindSafe + ?Sized,
[src]
T: Send + Sync + UnwindSafe + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src][+]
T: Clone,
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>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src][+]
V: MultiLane<T>,