“Floating-Point Printing and Parsing Can Be Simple And Fast”

The fastest known floating-point printer and parsing algorithms - fixed-width printing, shortest-width printing, and parsing, all in 400 lines of Go.

https://research.swtch.com/fp
https://research.swtch.com/fp-proof

research!rsc: Floating-Point Printing and Parsing Can Be Simple And Fast (Floating Point Formatting, Part 3)

@rsc an aside, but regarding the `bool2` function, is it recognized and handled properly due to the broader context? The reason I ask is that I seem to recall an older Go issue where the compiler will recognize assigning a local variable and returning that, but not this form with a conditional return. And it looks like it is still the case when compiled individually: https://godbolt.org/z/s3dcEfrxf
Compiler Explorer - Go (x86-64 gc 1.25.4)

package p // bool2 converts b to an integer: 1 for true, 0 for false. func bool2(b bool) int { if b { return 1 } return 0 } // I thought this format is required for Go compiler to remove it? func bool2Alt(b bool) (n int) { if b { n = 1 } return }

@inr Yes, it works when inlined. https://godbolt.org/z/97P368jq4
Compiler Explorer - Go (x86-64 gc 1.25.7)

package p // bool2 converts b to an integer: 1 for true, 0 for false. func bool2(b bool) int { if b{ return 1 } return 0 } func f(x, y int) int { return 5 + bool2(x==y) }