exactnum

package
v1.10.0-alpha.10 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package exactnum owns exact finite arithmetic shared by design analysis and runtime JSON schema matching. Source adapters admit syntax independently of this representation; target decoding precision never changes numeric meaning.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Domain

type Domain struct {
	// Bits is the carrier width.
	Bits int
	// Float selects an IEEE floating carrier rather than an integer carrier.
	Float bool
	// Unsigned selects an unsigned integer carrier.
	Unsigned bool
}

Domain identifies a finite native numeric carrier. Integer widths are 1..64; floating widths are 32 or 64. Unsigned applies only to integers.

func (Domain) Limits

func (d Domain) Limits() (any, any)

Limits returns the finite minimum and maximum native values of the domain, using the same scalar representations as Boundary.

type Number

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

Number is an immutable finite number, sign*C*2^E2*5^E5. The coefficient is positive and has no factors of two or five. Exponents have arbitrary magnitude. Its zero value is zero. Copies share private immutable storage safely.

func FromFloat64

func FromFloat64(value float64) (Number, error)

FromFloat64 preserves the actual finite binary value, not its short decimal spelling. Converting a float32 to float64 before calling this is exact.

func FromInt64

func FromInt64(value int64) Number

FromInt64 preserves an integer exactly.

func FromInteger

func FromInteger(value *big.Int) Number

FromInteger copies an arbitrary-size integer into immutable numeric storage.

func FromScalar

func FromScalar(value any) (Number, bool)

FromScalar reads the exact value of an already admitted Go numeric scalar, including named numeric types. It does not decide source-type eligibility.

func FromUint64

func FromUint64(value uint64) Number

FromUint64 preserves an unsigned integer exactly.

func ParseDSL

func ParseDSL(source string) (Number, error)

ParseDSL preserves the existing finite strconv.ParseFloat string admission contract, including hexadecimal, separators and underflowing nonzero inputs. The rounded parse result is used only to reject nonfinite sources, never as the retained numeric value.

func ParseJSON

func ParseJSON(source string) (Number, error)

ParseJSON admits a JSON number and preserves its exact mathematical meaning. JSON whitespace around the token is allowed; quoted numbers are not numbers.

func (Number) Boundary

func (n Number) Boundary(domain Domain, lower, exclusive bool) (any, bool)

Boundary returns the first native value satisfying a lower bound, or the last satisfying an upper bound. Exclusive removes exact equality. False means no value in the domain satisfies the bound. Integers return int64 or uint64; floats return their exact native width. It never expands an endpoint's powers. An invalid internal carrier description panics.

func (Number) Cmp

func (n Number) Cmp(other Number) int

Cmp returns -1, 0 or 1 according to the exact ordering of n and other.

func (Number) IsInt

func (n Number) IsInt() bool

IsInt reports whether n is mathematically integral without expanding powers.

func (Number) Key

func (n Number) Key() string

Key returns a canonical exact identity without expanding exponent magnitudes. It is an internal identity spelling, not JSON or DSL syntax.

func (Number) MarshalJSON

func (n Number) MarshalJSON() ([]byte, error)

MarshalJSON emits an unquoted exact numeric token.

func (Number) MarshalJSONTo

func (n Number) MarshalJSONTo(encoder *jsontext.Encoder) error

MarshalJSONTo emits an unquoted exact numeric token through JSON v2.

func (Number) MarshalYAML

func (n Number) MarshalYAML() (any, error)

MarshalYAML emits an exact numeric scalar. Explicit node tags retain numeric meaning even when a YAML implementation cannot decode the token into float64.

func (Number) Sign

func (n Number) Sign() int

Sign returns -1, 0 or 1 according to the sign of n.

func (Number) String

func (n Number) String() string

String returns a canonical exact JSON numeric token. A binary-radix input can intrinsically require output proportional to its decimal expansion.

Jump to

Keyboard shortcuts

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