Documentation
¶
Index ¶
- Variables
- type Num
- func (n Num) Abs() Num
- func (n Num) BigInt() *big.Int
- func (n Num) FitsInPrecision(prec int32) bool
- func (n Num) HighBits() int64
- func (n Num) IncreaseScaleBy(increase int32) Num
- func (n Num) Less(other Num) bool
- func (n Num) LowBits() uint64
- func (n Num) Negate() Num
- func (n Num) ReduceScaleBy(reduce int32, round bool) Num
- func (n Num) Rescale(originalScale, newScale int32) (out Num, err error)
- func (n Num) Sign() int
- func (n Num) ToFloat32(scale int32) float32
- func (n Num) ToFloat64(scale int32) float64
Constants ¶
This section is empty.
Variables ¶
var (
MaxDecimal128 = New(542101086242752217, 687399551400673280-1)
)
Functions ¶
This section is empty.
Types ¶
type Num ¶
type Num struct {
// contains filtered or unexported fields
}
Num 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
func FromBigInt ¶
FromBigInt will convert a big.Int to a Num, if the value in v has a BitLen > 128, this will panic.
func FromFloat32 ¶
FromFloat32 returns a new decimal128.Num constructed from the given float32 value using the provided precision and scale. Will return an error if the value cannot be accurately represented with the desired precision and scale.
func FromFloat64 ¶
FromFloat64 returns a new decimal128.Num constructed from the given float64 value using the provided precision and scale. Will return an error if the value cannot be accurately represented with the desired precision and scale.
func (Num) BigInt ¶
while the code would be simpler to just do lsh/rsh and add it turns out from benchmarking that calling SetBits passing in the words and negating ends up being >2x faster
func (Num) FitsInPrecision ¶
FitsInPrecision returns true or false if the value currently held by n would fit within precision (0 < prec <= 38) without losing any data.
func (Num) HighBits ¶
HighBits returns the high bits of the two's complement representation of the number.
func (Num) IncreaseScaleBy ¶
IncreaseScaleBy returns a new decimal128.Num with the value scaled up by the desired amount. Must be 0 <= increase <= 38. Any data loss from scaling is ignored. If you wish to prevent data loss, use Rescale which will return an error if data loss is detected.
func (Num) LowBits ¶
LowBits returns the low bits of the two's complement representation of the number.
func (Num) ReduceScaleBy ¶
ReduceScaleBy returns a new decimal128.Num with the value scaled down by the desired amount and, if 'round' is true, the value will be rounded accordingly. Assumes 0 <= reduce <= 38. Any data loss from scaling is ignored. If you wish to prevent data loss, use Rescale which will return an error if data loss is detected.
func (Num) Rescale ¶
Rescale returns a new decimal128.Num with the value updated assuming the current value is scaled to originalScale with the new value scaled to newScale. If rescaling this way would cause data loss, an error is returned instead.