Help us shape the future of Go! Take the 2026 Go Developer Survey

dynamonum

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package dynamonum implements DynamoDB's exact decimal Number type: up to 38 significant digits, magnitude 1E-130..9.9999999999999999999999999999999999999E+125.

Index

Constants

View Source
const (
	// MaxDigits is the maximum number of significant digits.
	MaxDigits = 38
)

Variables

View Source
var (
	// ErrInvalid is returned for text that is not a decimal number.
	ErrInvalid = errors.New("not a valid number")
	// ErrOverflow is returned when the magnitude exceeds the supported range.
	ErrOverflow = errors.New(
		"Number overflow. Attempting to store a number with magnitude larger than supported range")
	// ErrUnderflow is returned when a non-zero magnitude is below the supported range.
	ErrUnderflow = errors.New(
		"Number underflow. Attempting to store a number with magnitude smaller than supported range")
	// ErrTooManyDigits is returned when a value needs more than 38 significant digits.
	ErrTooManyDigits = errors.New(
		"Attempting to store more than 38 significant digits in a Number")
)

Functions

func Canonical

func Canonical(s string) string

Canonical returns s with redundant zeros, exponent and sign normalised, as DynamoDB stores numbers. Invalid text and text with meaningless leading zeros ("007") is returned unchanged so validation can reject it.

Types

type Num

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

Num is a normalised decimal: value = (+/-) d[:n] * 10^scale, with no leading or trailing zero digit. Non-zero integers of at most 18 digits are held only in small (the fast path); the digit fields are then unset. The zero value is zero. Equal values have equal representations, so Num is comparable with ==.

func Add

func Add(x, y Num) (Num, error)

Add returns x+y, or an error when the result leaves the supported range or precision.

func FromFloat

func FromFloat(f float64) (Num, bool)

FromFloat converts a float64 via its shortest decimal form; false if not finite or out of range.

func FromInt64

func FromInt64(v int64) Num

FromInt64 converts an integer.

func Parse

func Parse(s string) (Num, error)

Parse parses and range-checks a DynamoDB number string.

func Sub

func Sub(x, y Num) (Num, error)

Sub returns x-y.

func (Num) Cmp

func (x Num) Cmp(y Num) int

Cmp returns -1, 0 or +1.

func (Num) IsZero

func (x Num) IsZero() bool

IsZero reports whether the value is zero.

func (Num) String

func (x Num) String() string

String renders canonical plain decimal text (no exponent, no redundant zeros).

Jump to

Keyboard shortcuts

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