Documentation
¶
Overview ¶
Package jsnum reads and writes numbers the way JavaScript does.
The writing half covers Number#toString (Format), String(x) (String) and Math.round (Round); the reading half covers parseInt (ParseInt, ParseHex) and parseFloat (ParseFloat). Operations need these to report the same figures CyberChef does, down to where the notation switches to exponential and which way a negative half rounds.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
Format writes a float the way JavaScript's Number#toString does. Go's %g agrees on the shortest round-trip digits but switches to exponential notation at different thresholds and spells the exponent differently, so the digits are taken from Go and the presentation is rebuilt here.
func IsHexDigit ¶
IsHexDigit reports whether c is an ASCII hexadecimal digit.
func ParseFloat ¶
ParseFloat mirrors JavaScript's parseFloat: skip leading whitespace, then parse the longest valid numeric prefix, yielding NaN when none is present.
func ParseHex ¶
ParseHex is parseInt(s, 16): it reads the leading hex digits and yields NaN when there are none. A 0x prefix is allowed and skipped, as it is for that radix.
func ParseInt ¶
ParseInt mimics JS parseInt(s, base) for base 10/16: skips leading whitespace and an optional sign, then consumes valid leading digits. ok is false when no digits are consumed (JS returns NaN).
func Round ¶
Round rounds half towards positive infinity, as JavaScript's Math.round does. Go's math.Round rounds halves away from zero, which differs for negatives such as -0.5.
func RoundFloat ¶
RoundFloat is Round without the narrowing to int.
Types ¶
This section is empty.