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 ¶
- type Domain
- type Number
- func (n Number) Boundary(domain Domain, lower, exclusive bool) (any, bool)
- func (n Number) Cmp(other Number) int
- func (n Number) IsInt() bool
- func (n Number) Key() string
- func (n Number) MarshalJSON() ([]byte, error)
- func (n Number) MarshalJSONTo(encoder *jsontext.Encoder) error
- func (n Number) MarshalYAML() (any, error)
- func (n Number) Sign() int
- func (n Number) String() string
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.
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 ¶
FromFloat64 preserves the actual finite binary value, not its short decimal spelling. Converting a float32 to float64 before calling this is exact.
func FromInteger ¶
FromInteger copies an arbitrary-size integer into immutable numeric storage.
func FromScalar ¶
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 ¶
FromUint64 preserves an unsigned integer exactly.
func ParseDSL ¶
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 ¶
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 ¶
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) Key ¶
Key returns a canonical exact identity without expanding exponent magnitudes. It is an internal identity spelling, not JSON or DSL syntax.
func (Number) MarshalJSON ¶
MarshalJSON emits an unquoted exact numeric token.
func (Number) MarshalJSONTo ¶
MarshalJSONTo emits an unquoted exact numeric token through JSON v2.
func (Number) MarshalYAML ¶
MarshalYAML emits an exact numeric scalar. Explicit node tags retain numeric meaning even when a YAML implementation cannot decode the token into float64.