Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
Public Member Functions | Static Public Member Functions | List of all members
arrow::Decimal128 Class Reference

Represents a signed 128-bit integer in two's complement. More...

#include <arrow/util/decimal.h>

Public Member Functions

constexpr Decimal128 (int64_t high, uint64_t low)
 Create an Decimal128 from the two's complement representation. More...
 
constexpr Decimal128 ()
 Empty constructor creates an Decimal128 with a value of 0. More...
 
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
constexpr Decimal128 (T value)
 Convert any integer value into an Decimal128. More...
 
 Decimal128 (const std::string &value)
 Parse the number from a base 10 string representation. More...
 
 Decimal128 (const uint8_t *bytes)
 Create an Decimal128 from an array of bytes. More...
 
Decimal128Negate ()
 Negate the current value. More...
 
Decimal128operator+= (const Decimal128 &right)
 Add a number to this one. The result is truncated to 128 bits. More...
 
Decimal128operator-= (const Decimal128 &right)
 Subtract a number from this one. The result is truncated to 128 bits. More...
 
Decimal128operator*= (const Decimal128 &right)
 Multiply this number by another number. The result is truncated to 128 bits. More...
 
Status Divide (const Decimal128 &divisor, Decimal128 *result, Decimal128 *remainder) const
 Divide this number by right and return the result. More...
 
Decimal128operator/= (const Decimal128 &right)
 In-place division. More...
 
 operator char () const
 Cast the value to char. This is used when converting the value a string. More...
 
Decimal128operator|= (const Decimal128 &right)
 Bitwise or between two Decimal128. More...
 
Decimal128operator &= (const Decimal128 &right)
 Bitwise and between two Decimal128. More...
 
Decimal128operator<<= (uint32_t bits)
 Shift left by the given number of bits. More...
 
Decimal128operator>>= (uint32_t bits)
 Shift right by the given number of bits. Negative values will. More...
 
int64_t high_bits () const
 Get the high bits of the two's complement representation of the number. More...
 
uint64_t low_bits () const
 Get the low bits of the two's complement representation of the number. More...
 
std::array< uint8_t, 16 > ToBytes () const
 Return the raw bytes of the value in little-endian byte order. More...
 
std::string ToString (int precision, int scale) const
 Convert the Decimal128 value to a base 10 decimal string with the given precision and scale. More...
 

Static Public Member Functions

static Status FromString (const std::string &s, Decimal128 *out, int *precision=NULLPTR, int *scale=NULLPTR)
 Convert a decimal string to an Decimal128 value, optionally including precision and scale if they're passed in and not null. More...
 

Detailed Description

Represents a signed 128-bit integer in two's complement.

Calculations wrap around and overflow is ignored.

For a discussion of the algorithms, look at Knuth's volume 2, Semi-numerical Algorithms section 4.3.1.

Adapted from the Apache ORC C++ implementation

Constructor & Destructor Documentation

◆ Decimal128() [1/5]

constexpr arrow::Decimal128::Decimal128 ( int64_t  high,
uint64_t  low 
)
inline

Create an Decimal128 from the two's complement representation.

◆ Decimal128() [2/5]

constexpr arrow::Decimal128::Decimal128 ( )
inline

Empty constructor creates an Decimal128 with a value of 0.

◆ Decimal128() [3/5]

template<typename T , typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
constexpr arrow::Decimal128::Decimal128 ( value)
inline

Convert any integer value into an Decimal128.

◆ Decimal128() [4/5]

arrow::Decimal128::Decimal128 ( const std::string &  value)
explicit

Parse the number from a base 10 string representation.

◆ Decimal128() [5/5]

arrow::Decimal128::Decimal128 ( const uint8_t *  bytes)
explicit

Create an Decimal128 from an array of bytes.

Bytes are assumed to be in little endian byte order.

Member Function Documentation

◆ Divide()

Status arrow::Decimal128::Divide ( const Decimal128 divisor,
Decimal128 result,
Decimal128 remainder 
) const

Divide this number by right and return the result.

This operation is not destructive. The answer rounds to zero. Signs work like: 21 / 5 -> 4, 1 -21 / 5 -> -4, -1 21 / -5 -> -4, 1 -21 / -5 -> 4, -1

Parameters
divisorthe number to divide by
remainderthe remainder after the division

◆ FromString()

static Status arrow::Decimal128::FromString ( const std::string &  s,
Decimal128 out,
int *  precision = NULLPTR,
int *  scale = NULLPTR 
)
static

Convert a decimal string to an Decimal128 value, optionally including precision and scale if they're passed in and not null.

◆ high_bits()

int64_t arrow::Decimal128::high_bits ( ) const
inline

Get the high bits of the two's complement representation of the number.

◆ low_bits()

uint64_t arrow::Decimal128::low_bits ( ) const
inline

Get the low bits of the two's complement representation of the number.

◆ Negate()

Decimal128& arrow::Decimal128::Negate ( )

Negate the current value.

◆ operator &=()

Decimal128& arrow::Decimal128::operator&= ( const Decimal128 right)

Bitwise and between two Decimal128.

◆ operator char()

arrow::Decimal128::operator char ( ) const
explicit

Cast the value to char. This is used when converting the value a string.

◆ operator*=()

Decimal128& arrow::Decimal128::operator*= ( const Decimal128 right)

Multiply this number by another number. The result is truncated to 128 bits.

◆ operator+=()

Decimal128& arrow::Decimal128::operator+= ( const Decimal128 right)

Add a number to this one. The result is truncated to 128 bits.

◆ operator-=()

Decimal128& arrow::Decimal128::operator-= ( const Decimal128 right)

Subtract a number from this one. The result is truncated to 128 bits.

◆ operator/=()

Decimal128& arrow::Decimal128::operator/= ( const Decimal128 right)

In-place division.

◆ operator<<=()

Decimal128& arrow::Decimal128::operator<<= ( uint32_t  bits)

Shift left by the given number of bits.

◆ operator>>=()

Decimal128& arrow::Decimal128::operator>>= ( uint32_t  bits)

Shift right by the given number of bits. Negative values will.

◆ operator|=()

Decimal128& arrow::Decimal128::operator|= ( const Decimal128 right)

Bitwise or between two Decimal128.

◆ ToBytes()

std::array<uint8_t, 16> arrow::Decimal128::ToBytes ( ) const

Return the raw bytes of the value in little-endian byte order.

◆ ToString()

std::string arrow::Decimal128::ToString ( int  precision,
int  scale 
) const

Convert the Decimal128 value to a base 10 decimal string with the given precision and scale.


The documentation for this class was generated from the following file: