MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / EncodeFloatAscending

Function EncodeFloatAscending

pkg/util/encoding/float.go:31–49  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

29// This ordering ensures that NaNs are always sorted first in either encoding
30// direction, and that after them a logical ordering is followed.
31func EncodeFloatAscending(b []byte, f float64) []byte {
32 // Handle the simplistic cases first.
33 switch {
34 case math.IsNaN(f):
35 return append(b, floatNaN)
36 case f == 0:
37 // This encodes both positive and negative zero the same. Negative zero uses
38 // composite indexes to decode itself correctly.
39 return append(b, floatZero)
40 }
41 u := math.Float64bits(f)
42 if u&(1<<63) != 0 {
43 u = ^u
44 b = append(b, floatNeg)
45 } else {
46 b = append(b, floatPos)
47 }
48 return EncodeUint64Ascending(b, u)
49}
50
51// EncodeFloatDescending is the descending version of EncodeFloatAscending.
52func EncodeFloatDescending(b []byte, f float64) []byte {

Callers 3

EncodeBox2DAscendingFunction · 0.85
EncodeUntaggedBox2DValueFunction · 0.85
EncodeFloatDescendingFunction · 0.85

Calls 1

EncodeUint64AscendingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…