Float 1.1 Is Not 1.1 (and the Wire Says So in the JSON)
The one number every beginner reaches for, 1.1, is the one that exposes float fields the fastest. A float field and a double field holding the same intent of one point one are different bytes on the wire, and the tool at proto.datajutsu.com prints them as different numbers. I encoded both against the tool's own engine and watched: the float comes out as the four bytes cd cc 8c 3f, the double as the eight bytes 9a 99 99 99 99 99 f1 3f, and the decode tab prints the float as 1.100000023841858 while the double prints as 1.1. That string of extra digits is not a display bug. It is the widening. The stored value is a 24 bit mantissa approximation, and the moment the JSON renderer shows it as a 53 bit double, the approximation has to be written out in full.
The capacity is the whole story, and it is about seven significant decimal digits in a float. I put pi into a float field and it came back as 3.1415927410125732, which is as close to pi as 24 bits of mantissa will manage. Put the double version of a number one plus two to the minus fifty second power into a float and it came back as exactly one. The last unit in the last place of a double is smaller than the step between two adjacent floats near one, so it rounds away and the difference simply stops existing. In the other direction, a JavaScript number at two to the fifty third plus one into a double field rounds to two to the fifty third before the encoder ever sees the value; the wire is not where that precision goes, the language's own number type is. The sibling story, where a 64-bit integer loses the same way without Long, is covered in the int64 precision post; floats lose earlier, and they lose it on purpose, because the format is built to trade range for precision.
The special values are where the JSON surprises people. The tool's decode tab runs with the json flag, and under it a float whose bits are not a number does not print as a number. Not-a-number prints as the string NaN. Positive infinity prints as the string Infinity, negative infinity as the string -Infinity. If you then pass that JSON to a strict consumer, it has to accept strings where it expected numbers, and if you pass it to a JSON parser that does not know the protobuf mapping, the field is still there, just wearing a type it never asked for. I measured the re-encode path too: handing the engine the string NaN writes the canonical not-a-number bit pattern, and it turns out the engine preserves the payload bits of a non-canonical pattern, forcing only the quiet bit. The payload of a not-a-number is not on the wire for the decoder, but it is in the bytes, and the engine does not throw it away.
There is a one-bit line between infinity and not-a-number, and it is easy to cross by accident. In the bit pattern, all-ones exponent with a zero fraction is positive infinity, all-ones exponent with the top fraction bit set is the canonical not-a-number. Everything between them is also a not-a-number with a different payload. A producer that hand-writes those four bytes, or a memory corruption that flips a single bit in a float, can turn your largest finite value into an infinity with one step and a not-a-number with another. Negative zero crosses the same line from the other side: I encoded negative zero and the four bytes carry the sign bit, 00 00 00 80, and the JSON prints it as a plain zero. The sign is invisible in the text, but it is on the wire, and if you re-encode the decoded value the sign comes back. Zero is also not free: an explicit positive zero writes four bytes, tag and all, because this engine writes explicit defaults rather than skipping them.
The input side is permissive in a way the spec is not. The official mapping says an out-of-range number string like 1e999999999 is an error. The engine does not argue; it hands it to the number constructor and gets an infinity, and encodes the infinity bits with no complaint. A string that is not a number at all, abc, becomes a not-a-number and gets its canonical bytes. A string below the smallest normal float, 1e to the minus forty fifth, becomes a denormal rather than zero or infinity, which is the right answer and not one you get from every implementation. A null at the field position drops the field entirely, four bytes gone with no note. All of this is the same class of permissiveness the encode mismatch post documents for the other scalar types; floats just add the infinity and not-a-number outcomes.
So the rules that fall out: a float holds about seven significant digits and a double about fifteen, and the difference shows up in the printed JSON as the exact extra digits of the approximation; the wire bytes for the same intent differ between the two types because the mantissa width differs; the special values print as strings, and a strict JSON consumer has to be told about that; and the one-bit boundaries between your maximum finite value, infinity, and not-a-number mean a single flipped bit in four bytes of a float can change what the field means. You can watch all of it against your own bytes in the tool at proto.datajutsu.com: paste the hex of a float field and see the widened value, or paste the bytes cd cc 8c 3f and see the number that is actually stored behind the one point one. The wire format post covers what fixed32 and fixed64 are at the byte level; this is what happens when the bytes do not name a number.