envzn
0.8 · beta · not released

Library / Numbers / Math / FloatFormat

CLASS

FloatFormat

Shortest-round-trippable float -> decimal string.

Fields 20

uint32 LOG2_OF_5_MULT
uint32 LOG2_OF_5_SHIFT
int32 LOG2_POW5_MAX_E
uint32 LOG10_OF_2_MULT
uint32 LOG10_OF_2_SHIFT
int32 LOG10_POW2_MAX_E
uint32 LOG10_OF_5_MULT
uint32 LOG10_OF_5_SHIFT
int32 LOG10_POW5_MAX_E
int32 DOUBLE_MANTISSA_BITS
int32 DOUBLE_EXPONENT_BITS
int32 DOUBLE_BIAS
int32 FLOAT_MANTISSA_BITS
int32 FLOAT_EXPONENT_BITS
int32 FLOAT_BIAS
int32 DOUBLE_POW5_INV_BITCOUNT
int32 DOUBLE_POW5_BITCOUNT
int32 FLOAT_POW5_INV_BITCOUNT
int32 FLOAT_POW5_BITCOUNT
int32 POW5_TABLE_SIZE

Methods 10

METHOD float64toDecimal(uint64 bits) RETURNS FloatingDecimal64
reads

Render the IEEE-754 double whose raw bits are bits as its shortest round-trippable decimal String.

METHOD floatingDecimalToString(FloatingDecimal64 fd, boolean isNegative) RETURNS String
reads

Turn a FloatingDecimal64 carrier into its final String, per the Phase 4 format-policy (floatformat-ryu-plan.md): Python-style threshold (sciExp < -4 OR >= 16), compact exponent (no '+', no leading zero), no trailing '.0', sign of zero dropped, special-case spellings "NaN"/"infinity"/"-infinity". MIRRORED by floatingDecimalToBytes — the two MUST stay byte-identical.

METHOD formatF64(uint64 bits) RETURNS String
reads

One-shot: bits → FloatingDecimal64 → String. Convenience wrapper that chains float64toDecimal + floatingDecimalToString, extracting the sign bit from the raw bits.

METHOD floatingDecimalToBytes(MUTABLE REFERENCE binary[] out, FloatingDecimal64 fd, boolean isNegative) RETURNS void
reads

MIRROR of floatingDecimalToString — appends the bytes to out.

METHOD appendF64Bits(MUTABLE REFERENCE binary[] out, uint64 bits) RETURNS void
reads

MIRROR of formatF64 — appends the bytes for the float whose raw bits are bits.

METHOD appendF64(MUTABLE REFERENCE binary[] out, float64 v) RETURNS void
reads

appendF64Bits from a float64 value — the serializer's entry point.

METHOD decimalF64(float64 v) RETURNS uint64
reads

The Ryu decomposition of a float64 value, without formatting: v == (isNegative ? -1 : 1) * mantissa * 10^exponent, the mantissa the shortest that round-trips. Specials keep float64toDecimal's sentinel exponents (0x7FFFFFFC..0x7FFFFFFF).

METHOD float32toDecimal(uint32 bits) RETURNS FloatingDecimal32
reads

Render the IEEE-754 float whose raw bits are bits as its shortest round-trippable decimal. Same structural shape as float64toDecimal above — re-read its STEP 1..5 comments for the algorithm narrative; this body only flags the f32 specifics (narrower mantissa, narrower magic constants, 32-bit arithmetic throughout).

METHOD floatingDecimal32ToString(FloatingDecimal32 fd, boolean isNegative) RETURNS String
reads

f32 sibling of floatingDecimalToString — identical logic; only the carrier type differs (FloatingDecimal32 vs FloatingDecimal64, uint32 vs uint64 mantissa). The shared digit-walking helpers (appendDigits, appendMantissaWithPoint, appendChars) take uint64 — uint32 mantissas widen at the call site.

METHOD formatF32(uint32 bits) RETURNS String
reads

One-shot: bits → FloatingDecimal32 → String.