Standard library referenceModules
i/float_text
The text form of a Float (§11.8): the shortest digits that read back as
the same Float, correctly rounded. core.inspect and every Float in an
inspected value use this function, so it uses no core.inspect itself.
The digit loop is the Dragon interval construction (Steele & White, “How to Print Floating-Point Numbers Accurately”, 1990; Burger & Dybvig, “Printing Floating-Point Numbers Quickly and Accurately”, 1996): the exact value and the two rounding midpoints are exact integers, so every decision is an integer comparison, also for subnormals and the largest finite value. No floating-point logarithm is used.
to_string
The shortest text that reads back as x.
float_text.to_string(0.1) // "0.1"
float_text.to_string(1.0e20) // "1.0e20"
float_text.to_string(-0.0025) // "-0.0025" to_string = (x : Float) -> String {