decimal128

package
v0.3.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2024 License: Apache-2.0, Apache-2.0, BSD-2-Clause, + 9 more Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func FromBigInt(v *big.Int) (n Num)

FromBigInt will convert a big.Int to a Num, if the value in v has a BitLen > 128, this will panic.

func FromI64

func FromI64(v int64) Num

FromI64 returns a new signed 128-bit integer value from the provided int64 one.

func FromU64

func FromU64(v uint64) Num

FromU64 returns a new signed 128-bit integer value from the provided uint64 one.

func New

func New(hi int64, lo uint64) Num

New returns a new signed 128-bit integer value.

func (Num) BigInt

func (n Num) BigInt() *big.Int

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) HighBits

func (n Num) HighBits() int64

HighBits returns the high bits of the two's complement representation of the number.

func (Num) LowBits

func (n Num) LowBits() uint64

LowBits returns the low bits of the two's complement representation of the number.

func (Num) Sign

func (n Num) Sign() int

Sign returns:

-1 if x < 0

0 if x == 0

+1 if x > 0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL