number

package
v1.32.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeCompact8

func DecodeCompact8(b Compact8) int64

DecodeCompact8 converts a Compact8 value to an int64.

Types

type Compact8

type Compact8 = uint8

Compact8 is an unsigned 8-bit compact integer encoding with 12 mantissa values per exponent level (instead of the standard power-of-2 split).

For a byte value b, let e = b / 12 and m = b % 12:

b=0:          0                        (zero)
e=0, m>=1:    m << (offset+1)          (subnormal)
e>=1:         (12+m) << (e+offset)     (normalized)

This gives approximately 8.3% relative precision (12 values per octave) and a representable range from 32 to 503316480 with offset 4.

func EncodeCompact8

func EncodeCompact8(value int64) Compact8

EncodeCompact8 encodes a non-negative int64 into Compact8 representation. The value is rounded down to the nearest representable value. Negative values go to 0 and values above the maximum representable go to 255.

func UpdateCompact8

func UpdateCompact8(value int64, prev Compact8) Compact8

UpdateCompact8 returns the Compact8 encoding of value, but with hysteresis: it sticks to prev unless the new code is significantly closer. This prevents oscillation when the underlying value fluctuates near a bucket boundary.

type Number

type Number struct {
	// contains filtered or unexported fields
}

func NewNumber

func NewNumber(
	value any,
) Number

func (Number) GetFloatOrDefault

func (n Number) GetFloatOrDefault(
	defaultValue float64,
) float64

func (Number) GetIntOrDefault

func (n Number) GetIntOrDefault(
	defaultValue int,
) int

func (Number) GetUintOrDefault

func (n Number) GetUintOrDefault(
	defaultValue uint,
) uint

type Type

type Type int
const (
	TypeUnknown Type = iota
	TypeFloat
	TypeInt
	TypeUint
)

Jump to

Keyboard shortcuts

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