number

package
v0.4.31 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UnicodeMinus = string([]rune{0x2212}) // unicode Minus sign, not accepted by math/big (*Float)Parse()
	ASCIIHyphen  = "-"                    // actual ASCII hyphen-minus character 0x2d
)

Functions

func Compare

func Compare(a, b *Number) int

func FindIndexes

func FindIndexes(input string) (start, point, end int)

FindIndexes tries to parse a number from the input string.

Goals:

  • numeric value identification find the right-most number in a string

Purpose:

  • numeric alignment: find the (virtual) position of the decimal point

  • numeric sorting: find the substring which can be converted into a number for numeric sorting

Notes:

  • unicode "minus" (u+2212) will be accepted for negation
  • Caution: unicode minus is NOT accepted by math/big.Float.Parse()!
  • unicode minus must be translated before parsing by math/big.Float
  • finding "numbers" in random strings is fuzzy at best
  • the indexes returned, should always be parsable by math/big.Float
  • if no number could be found, the "end" index will be 0

Types

type Number

type Number struct {

	// alignment info
	AlignIndex int // index of the decimal point within the field.Encoded string

	// numerical value
	Value *big.Float // numerical value of a field
}

Number represents a single numeric value, used for sorting and alignment.

Number structs are only intended for use for rendering, in [field.Field] structs.

See also: [version.Version]

func FromString

func FromString(in string) *Number

FromString parses the right-most numerical value from a string.

If a number could be found, the number will be returned allong with the index of the (possibly virtual) decimal point in the input string.

Jump to

Keyboard shortcuts

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