Documentation
¶
Overview ¶
Package num provides XSD numeric parsing and comparison helpers. Returned values may share backing storage with input slices.
Index ¶
- Variables
- func CompareFloat(a float64, ac FloatClass, b float64, bc FloatClass) (int, bool)
- func EncodeDecKey(dst []byte, v Dec) []byte
- func ParseDec(b []byte) (Dec, *ParseError)
- func ParseDecInto(b, dst []byte) (Dec, []byte, *ParseError)
- func ParseFloat(b []byte, bits int) (float64, FloatClass, *ParseError)
- func ParseFloat32(b []byte) (float32, FloatClass, *ParseError)
- func ParseInt(b []byte) (Int, *ParseError)
- type Dec
- type FloatClass
- type Int
- type ParseErrKind
- type ParseError
Constants ¶
This section is empty.
Variables ¶
var ( // IntZero is the zero value reused by numeric parsers. IntZero = Int{Sign: 0, Digits: zeroDigits} // Signed integer bounds reused during range checks. MinInt8 = Int{Sign: -1, Digits: []byte("128")} MaxInt8 = Int{Sign: 1, Digits: []byte("127")} MinInt16 = Int{Sign: -1, Digits: []byte("32768")} MaxInt16 = Int{Sign: 1, Digits: []byte("32767")} MinInt32 = Int{Sign: -1, Digits: []byte("2147483648")} MaxInt32 = Int{Sign: 1, Digits: []byte("2147483647")} MinInt64 = Int{Sign: -1, Digits: []byte("9223372036854775808")} MaxInt64 = Int{Sign: 1, Digits: []byte("9223372036854775807")} // Unsigned integer bounds reused during range checks. MaxUint8 = Int{Sign: 1, Digits: []byte("255")} MaxUint16 = Int{Sign: 1, Digits: []byte("65535")} MaxUint32 = Int{Sign: 1, Digits: []byte("4294967295")} MaxUint64 = Int{Sign: 1, Digits: []byte("18446744073709551615")} )
Functions ¶
func CompareFloat ¶ added in v0.0.24
func CompareFloat(a float64, ac FloatClass, b float64, bc FloatClass) (int, bool)
CompareFloat compares two parsed float/double values. The boolean result is false when either side is NaN (unordered).
func EncodeDecKey ¶
EncodeDecKey appends the canonical decimal key encoding to dst.
func ParseDec ¶
func ParseDec(b []byte) (Dec, *ParseError)
ParseDec parses a decimal lexical value into a Dec. The returned Dec may share backing storage with b.
func ParseDecInto ¶
func ParseDecInto(b, dst []byte) (Dec, []byte, *ParseError)
ParseDecInto parses a decimal lexical value into a Dec using dst as scratch. The returned Dec may share backing storage with b or dst.
func ParseFloat ¶ added in v0.0.24
func ParseFloat(b []byte, bits int) (float64, FloatClass, *ParseError)
ParseFloat parses an XSD float/double lexical value for the requested bit size.
func ParseFloat32 ¶
func ParseFloat32(b []byte) (float32, FloatClass, *ParseError)
ParseFloat32 parses an XSD float lexical value.
func ParseInt ¶
func ParseInt(b []byte) (Int, *ParseError)
ParseInt parses an integer lexical value into an Int. The returned Int may share backing storage with b.
Types ¶
type Dec ¶
Dec represents an arbitrary-precision decimal.
func AddDecInt ¶ added in v0.0.22
AddDecInt adds an integer delta to a decimal value without narrowing.
func DecFromScaledInt ¶ added in v0.0.19
DecFromScaledInt converts an Int scaled by 10^scale into a Dec.
func (Dec) RenderCanonical ¶
RenderCanonical appends the canonical lexical form to dst.
type FloatClass ¶
type FloatClass uint8
FloatClass identifies the ordering class of a float value.
const ( FloatFinite FloatClass = iota FloatPosInf FloatNegInf FloatNaN )
type Int ¶
Int represents an arbitrary-precision integer.
func DecToScaledInt ¶ added in v0.0.19
DecToScaledInt converts a Dec into an Int scaled by 10^scale. It truncates fractional digits when scale < dec.Scale.
func DecToScaledIntExact ¶ added in v0.0.19
DecToScaledIntExact converts a Dec into an Int scaled by 10^scale. It returns an error if non-zero fractional digits would be lost.
func FromUint64 ¶
FromUint64 returns an Int representation of a non-negative uint64.
func (Int) RenderCanonical ¶
RenderCanonical appends the canonical lexical form to dst.
type ParseErrKind ¶
type ParseErrKind uint8
ParseErrKind identifies a parse failure category.
const ( ParseInvalid ParseErrKind = iota ParseEmpty ParseBadChar ParseMultipleSigns ParseMultipleDots ParseNoDigits )
func (ParseErrKind) String ¶
func (k ParseErrKind) String() string
String returns a stable label for the parse error kind.
type ParseError ¶
type ParseError struct {
Kind ParseErrKind
}
ParseError represents a numeric parse failure.
func ValidateFloatLexical ¶
func ValidateFloatLexical(b []byte) *ParseError
ValidateFloatLexical checks whether a float/double lexical form is valid.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
Error returns the formatted error message.