Struct tidb_query_datatype::codec::mysql::decimal::Decimal[][src]

#[repr(C)]pub struct Decimal {
    int_cnt: u8,
    frac_cnt: u8,
    result_frac_cnt: u8,
    negative: bool,
    word_buf: [u32; 9],
}

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: boolword_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:

  1. the index of first non-zero word in self.word_buf to hold the leading ‘prec’ number of digits
  2. 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]

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]

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]

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]

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:

  1. empty string
  2. 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:

  1. an empty string
  2. 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]

type Output = Res<Decimal>

The resulting type after applying the + operator.

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]

fn convert(&self, _: &mut EvalContext) -> Result<Decimal>[src]

Convert a float number to decimal.

This function will use float’s canonical string representation rather than the accurate value the float represent.

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]

fn convert(&self, ctx: &mut EvalContext) -> Result<Decimal>[src]

Port from TiDB’s types.ConvertJSONToDecimal

impl<'a> ConvertTo<Decimal> for JsonRef<'a>[src]

fn convert(&self, ctx: &mut EvalContext) -> Result<Decimal>[src]

Port from TiDB’s types.ConvertJSONToDecimal

impl ConvertTo<Decimal> for Duration[src]

fn convert(&self, _: &mut EvalContext) -> Result<Decimal>[src]

This function should not return err, if it return err, then the err is because of bug.

Port from TiDB’ Duration::ToNumber

impl ConvertTo<Json> for Decimal[src]

impl ConvertTo<f64> for Decimal[src]

fn convert(&self, _: &mut EvalContext) -> Result<f64>[src]

This function should not return err, if it return err, then the err because of bug.

Port from TiDB’s MyDecimal::ToFloat64.

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]

type Output = Option<Res<Decimal>>

The resulting type after applying the / operator.

impl Eq for Decimal[src]

impl Evaluable for Decimal[src]

impl EvaluableRet for Decimal[src]

type ChunkedType = ChunkedVecSized<Self>

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]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for Decimal[src]

impl<'a, 'b> Mul<&'a Decimal> for &'b Decimal[src]

type Output = Res<Decimal>

The resulting type after applying the * operator.

impl Neg for Decimal[src]

type Output = Decimal

The resulting type after applying the - operator.

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]

type Output = Option<Res<Decimal>>

The resulting type after applying the % operator.

impl Rem<Decimal> for Decimal[src]

type Output = Option<Res<Decimal>>

The resulting type after applying the % operator.

impl<'a, 'b> Sub<&'a Decimal> for &'b Decimal[src]

type Output = Res<Decimal>

The resulting type after applying the - operator.

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<V, W> ConvertFrom<W> for V where
    W: ConvertTo<V>, 
[src]

impl<T> ConvertTo<NotNan<f64>> for T where
    T: ConvertTo<f64> + EvaluableRet
[src]

impl<T> ConvertTo<String> for T where
    T: ToString + EvaluableRet
[src]

impl<T> ConvertTo<Vec<u8, Global>> for T where
    T: ToString + EvaluableRet
[src]

impl<T> ConvertTo<i64> for T where
    T: ToInt
[src]

impl<T> ConvertTo<u64> for T where
    T: ToInt
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

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]

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T> Sealed<T> for T where
    T: ?Sized
[src]

impl<T> SendSyncUnwindSafe for T where
    T: Send + Sync + UnwindSafe + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]