Float32 writes a float32.
(val float32)
| 106 | |
| 107 | // Float32 writes a float32. |
| 108 | func (writer *Writer) Float32(val float32) { |
| 109 | // Float encoding produces byte-comparable serialized values when looking at the exponent and mantissa. This means |
| 110 | // that we just have to flip to exponent and mantissa for negative values, and flip the sign bit so that negatives |
| 111 | // sort before positives. To do this, we take advantage of arithmetic shifting by casting to a signed integer to |
| 112 | // create a mask that only exists for negative values. |
| 113 | uval := math.Float32bits(val) |
| 114 | uval ^= uint32(int32(uval)>>31) & 0x7FFFFFFF |
| 115 | uval ^= 0x80000000 |
| 116 | writer.Uint32(uval) |
| 117 | } |
| 118 | |
| 119 | // Float64 writes a float64. |
| 120 | func (writer *Writer) Float64(val float64) { |