decimal

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package decimal provides bounded decimal coefficients.

Index

Constants

This section is empty.

Variables

View Source
var ErrOverflow = errors.New("decimal coefficient overflow")

ErrOverflow indicates a coefficient exceeds 38 decimal digits.

Functions

This section is empty.

Types

type Int128

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

Int128 is a signed decimal coefficient with at most 38 digits. Its zero value represents zero.

func FromInt64

func FromInt64(v int64) Int128

FromInt64 constructs a coefficient from an integer.

func (Int128) Add

func (n Int128) Add(other Int128) (Int128, error)

Add returns the sum of two coefficients, or ErrOverflow if it exceeds 38 digits.

func (Int128) AddInt64

func (n Int128) AddInt64(v int64) (Int128, error)

AddInt64 returns the sum of the coefficient and an integer.

func (Int128) Cmp

func (n Int128) Cmp(other Int128) int

Cmp compares two coefficients and returns -1, 0, or 1.

func (Int128) CmpScaled

func (n Int128) CmpScaled(scale uint8, other Int128, otherScale uint8) int

CmpScaled compares coefficients interpreted with their respective scales. Scales must be between 0 and 18.

func (Int128) String

func (n Int128) String(scale uint8) string

String formats the coefficient with the given decimal scale.

Jump to

Keyboard shortcuts

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