Converting floats to strings
corsix.org
corsix.org
This sentence is crucial for anyone wants to implement the float-to-decimal conversion. There exists a Grisu-inspired analogue for this problem but to my current knowledge it is not well described in any known literature. I had to fully analyze the analogue and recreate my (slightly improved) version of the algorithm for Rust [1]. It is not too complex once you understood but annoying enough to derive again.
[1] https://github.com/rust-lang/rust/blob/f8d485f/src/libcore/n...
[1] https://github.com/LuaJIT/LuaJIT/blob/cf2dfaf3b4eef9b2de32d3...
Starts with an int->string conversion, then does the rest with string manipulation - strings, of course, being bignums with a somewhat wasteful BCD representation.
He missed an opportunity to name the article "Floating Point to Decimal Conversion is Easy and Not Fast" (in reference to https://swtch.com/~rsc/regexp/regexp1.html)
(When did he start writing articles in Go? IMHO the syntax is close enough to C to make skimming through easy enough, but confusing to look at in detail for the majority who will have likely far more experience with C than Go.)
You don't convert a car to a photograph when you take a picture, and neither do you do any "conversion" when you construct a string that represents the same value as is represented by the bit pattern of your double or float.
This sounds like some weird linguistic pedantry, and perhaps it is, but I suspect this usage causes confusion for a number of beginning programmers.
To me a "conversion" would have to be something like a static cast.
Disclaimer: I'm not a native speaker and have trouble differentiating between programming jargon and normal English. Sometimes I forget strings can also be made of yarn instead of text...
To (almost) keep with the analogy, it's okay to say a car was converted to a picture if it was squashed to be almost flat, framed and hung on a wall somehow. Some type conversions are highly destructive whereas others are trivial, like converting a table to a desk.
To push the analogy even further I couldn't convert a car to a photograph exactly as the types are incompatable, like a float and an array (at least in most programming languages).
When there is data loss, I personally prefer the term "string representation"