numutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float64

func Float64(value any) (float64, error)

func Int64Exact

func Int64Exact(value any) (int64, bool)

Int64Exact extracts an exact int64 from value without a float64 hop. It reports ok=false when the value is not integral, overflows int64, or has a type it cannot losslessly interpret; callers then fall back to the float64 path (which keeps today's semantics).

func OptionalFloat64FromPointer

func OptionalFloat64FromPointer[T NumericScalar](value *T) (parsed float64, omitted bool, err error)

OptionalFloat64FromPointer converts an optional numeric pointer to float64; a nil pointer reports omitted=true.

func OptionalPointerValue

func OptionalPointerValue[T any](value *T) (T, bool)

OptionalPointerValue dereferences an optional pointer; a nil pointer reports omitted=true with the zero value.

func ToFloat64

func ToFloat64(value any) (float64, bool)

func TryParseNumber

func TryParseNumber(s string) any

TryParseNumber parses s as int64, then float64, falling back to the raw string. Integral spellings in decimal or exponent form ("42.0", "9.007199254740993e15", "1.5e3"), and the hex-float and underscore forms ParseFloat also accepts ("0x1p4", "1_000"), refine to exact int64 when they fit (#357). ParseFloat is the sole acceptance authority — the refinement runs only on strings it already accepted, so the grammar neither widens (rational syntax like "1/3" stays a raw string) nor narrows. Integral values beyond int64 range and genuinely fractional literals — including nonzero literals that underflow float64 to zero — stay float64.

Types

type NumericScalar

type NumericScalar interface {
	~float64 | ~float32 | ~int | ~int16 | ~int32 | ~int64
}

NumericScalar constrains the numeric scalar types shared by the pointer helpers.

Jump to

Keyboard shortcuts

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