javanum

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package javanum ports the JDK's floating-point text parsers, Double.parseDouble and Float.parseFloat (FloatingDecimal .readJavaFormatString), which Java's record layer uses for CAST(string AS DOUBLE/FLOAT) and for index options. Go's strconv grammar differs (it accepts "inf", "nan" and digit underscores and refuses signs on NaN, the f/F/d/D suffixes and out-of-range magnitudes), and its NaN is not Java's.

Index

Constants

View Source
const (
	NaN64Bits uint64 = 0x7ff8000000000000
	NaN32Bits uint32 = 0x7fc00000
)

NaN64Bits and NaN32Bits are Double.NaN and Float.NaN, the one NaN each parser returns: Go's math.NaN() is 0x7ff8000000000001, which packs to a different index key and record byte than the NaN Java writes.

Variables

This section is empty.

Functions

func NaN32

func NaN32() float32

NaN32 is Float.NaN.

func NaN64

func NaN64() float64

NaN64 is Double.NaN.

func ParseDouble

func ParseDouble(s string) (float64, error)

ParseDouble is Double.parseDouble: the value trimmed of characters at or below U+0020, then an optional sign and "NaN" or "Infinity", or a hexadecimal significand with its required binary exponent ("0x1.8p1"), or ASCII decimal digits with an optional point (at least one digit) and exponent, each optionally ended by one of f, F, d or D. A magnitude too large is an infinity and one too small a zero; every NaN is Double.NaN.

func ParseFloat

func ParseFloat(s string) (float32, error)

ParseFloat is Float.parseFloat: ParseDouble's grammar, the value rounded once, directly to binary32 (never through a double, which can round twice); every NaN is Float.NaN.

Types

type FormatError

type FormatError struct {
	// Input is the refused text, trimmed as the parser trims it.
	Input string
	// Text, when set, is the exception's own message instead of
	// forInputString's: "empty String" for a value that trims to nothing and
	// "multiple points" for a second point in the significand.
	Text string
}

FormatError is Java's NumberFormatException from the parsers.

func (*FormatError) Error

func (e *FormatError) Error() string

Error is the exception's getMessage().

type IllegalArgumentError

type IllegalArgumentError struct {
	Message string
}

IllegalArgumentError is Java's IllegalArgumentException. It lives here, below both the record layer and the R-tree, so either can raise it and errors.As matches one type.

func (*IllegalArgumentError) Error

func (e *IllegalArgumentError) Error() string

type IllegalStateError

type IllegalStateError struct {
	Message string
}

IllegalStateError is Java's IllegalStateException. It lives here, below both the record layer and the R-tree, so either can raise it and errors.As matches one type.

func (*IllegalStateError) Error

func (e *IllegalStateError) Error() string

Jump to

Keyboard shortcuts

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