EncodeFloatAscending returns the resulting byte slice with the encoded float64 appended to b. The encoded format for a float64 value f is, for positive f, the encoding of the 64 bits (in IEEE 754 format) re-interpreted as an int64 and encoded using EncodeUint64Ascending. For negative f, we keep the
(b []byte, f float64)
| 34 | // This ordering ensures that NaNs are always sorted first in either encoding |
| 35 | // direction, and that after them a logical ordering is followed. |
| 36 | func EncodeFloatAscending(b []byte, f float64) []byte { |
| 37 | // Handle the simplistic cases first. |
| 38 | switch { |
| 39 | case math.IsNaN(f): |
| 40 | return append(b, floatNaN) |
| 41 | case f == 0: |
| 42 | // This encodes both positive and negative zero the same. Negative zero uses |
| 43 | // composite indexes to decode itself correctly. |
| 44 | return append(b, floatZero) |
| 45 | } |
| 46 | u := math.Float64bits(f) |
| 47 | if u&(1<<63) != 0 { |
| 48 | u = ^u |
| 49 | b = append(b, floatNeg) |
| 50 | } else { |
| 51 | b = append(b, floatPos) |
| 52 | } |
| 53 | return EncodeUint64Ascending(b, u) |
| 54 | } |
| 55 | |
| 56 | // EncodeFloatDescending is the descending version of EncodeFloatAscending. |
| 57 | func EncodeFloatDescending(b []byte, f float64) []byte { |
no test coverage detected
searching dependent graphs…