本文整理汇总了Golang中math.Float64bits函数的典型用法代码示例。如果您正苦于以下问题:Golang Float64bits函数的具体用法?Golang Float64bits怎么用?Golang Float64bits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Float64bits函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: encodeValue
// encodeValue encodes db value from metric.
func encodeValue(m *models.Metric) []byte {
b := make([]byte, 8+8+8)
binary.BigEndian.PutUint64(b[:8], math.Float64bits(m.Value))
binary.BigEndian.PutUint64(b[8:8+8], math.Float64bits(m.Score))
binary.BigEndian.PutUint64(b[8+8:], math.Float64bits(m.Average))
return b
}
示例2: formatBinaryValue
func formatBinaryValue(value interface{}) ([]byte, error) {
switch v := value.(type) {
case int8:
return Uint64ToBytes(uint64(v)), nil
case int16:
return Uint64ToBytes(uint64(v)), nil
case int32:
return Uint64ToBytes(uint64(v)), nil
case int64:
return Uint64ToBytes(uint64(v)), nil
case int:
return Uint64ToBytes(uint64(v)), nil
case uint8:
return Uint64ToBytes(uint64(v)), nil
case uint16:
return Uint64ToBytes(uint64(v)), nil
case uint32:
return Uint64ToBytes(uint64(v)), nil
case uint64:
return Uint64ToBytes(uint64(v)), nil
case uint:
return Uint64ToBytes(uint64(v)), nil
case float32:
return Uint64ToBytes(math.Float64bits(float64(v))), nil
case float64:
return Uint64ToBytes(math.Float64bits(v)), nil
case []byte:
return v, nil
case string:
return hack.Slice(v), nil
default:
return nil, errors.Errorf("invalid type %T", value)
}
}
示例3: Marshal
// Marshal serialized the Frame into bytes. We'll
// reuse the space pointed to by buf if there is
// sufficient space in it. We return the bytes
// that we wrote, plus any error.
func (f *Frame) Marshal(buf []byte) ([]byte, error) {
n := f.NumBytes()
var m []byte
if int64(len(buf)) >= n {
m = buf[:n]
} else {
m = make([]byte, n)
}
binary.LittleEndian.PutUint64(m[:8], uint64(f.Prim))
if n == 8 {
return m, nil
}
pti := f.GetPTI()
switch pti {
case PtiOneInt64:
binary.LittleEndian.PutUint64(m[8:16], uint64(f.Ude))
case PtiOneFloat64:
binary.LittleEndian.PutUint64(m[8:16], math.Float64bits(f.V0))
case PtiTwo64:
binary.LittleEndian.PutUint64(m[8:16], math.Float64bits(f.V0))
binary.LittleEndian.PutUint64(m[16:24], uint64(f.Ude))
case PtiUDE:
binary.LittleEndian.PutUint64(m[8:16], uint64(f.Ude))
if n == 16 {
return m, nil
}
copy(m[16:], f.Data)
m[n-1] = 0
}
return m, nil
}
示例4: marshal
func marshal() (outstring []string) {
// <bandcount>|trackname|beat0band0lbeat0band0r...Beat0bandNr
// numbers aren't intended to be human readable, but it is easier to emit human readable integers
out := make([]string, 0)
out = append(out, fmt.Sprintf("%d", bands))
for _, track := range sources {
out = append(out, fmt.Sprintf("|%s|%d|", track.filename, len(track.beats)))
if len(track.beats) <= 128 {
for i := uint(0); i < bands; i += 1 {
for j := uint(0); j < uint(len(track.beats)); j += 1 {
// fmt.Fprintf(os.Stderr, "%d %d %f %f\n", i, j, track.beats[j].buckets[i].left, track.beats[j].buckets[i].right)
}
}
}
for _, beat := range track.beats {
for _, band := range beat.buckets {
l := math.Float64bits(band.left)
r := math.Float64bits(band.right)
var sb bytes.Buffer
binary.Write(&sb, binary.BigEndian, l)
binary.Write(&sb, binary.BigEndian, r)
out = append(out, sb.String())
}
}
}
return out
}
示例5: Blake2b
// Blake2b returns the 64-byte BLAKE2b cryptographic
// hash of the Frame. This is useful for hashing and
// de-duplicating a stream of Frames.
//
// reference: https://godoc.org/github.com/codahale/blake2
// reference: https://blake2.net/
// reference: https://tools.ietf.org/html/rfc7693
//
func (f *Frame) Blake2b() []byte {
h, err := blake2b.New(nil)
panicOn(err)
n := f.NumBytes()
var m [24]byte
binary.LittleEndian.PutUint64(m[:8], uint64(f.Prim))
switch {
case n == 8:
h.Write(m[:8])
default:
pti := f.GetPTI()
switch pti {
case PtiOneInt64:
binary.LittleEndian.PutUint64(m[8:16], uint64(f.Ude))
h.Write(m[:16])
case PtiOneFloat64:
binary.LittleEndian.PutUint64(m[8:16], math.Float64bits(f.V0))
h.Write(m[:16])
case PtiTwo64:
binary.LittleEndian.PutUint64(m[8:16], math.Float64bits(f.V0))
binary.LittleEndian.PutUint64(m[16:24], uint64(f.Ude))
h.Write(m[:24])
case PtiUDE:
binary.LittleEndian.PutUint64(m[8:16], uint64(f.Ude))
h.Write(m[:16])
h.Write(f.Data)
}
}
return []byte(h.Sum(nil))
}
示例6: fop
// turn uint64 op into float64 op
func fop(f func(x, y uint64) uint64) func(x, y float64) float64 {
return func(x, y float64) float64 {
bx := math.Float64bits(x)
by := math.Float64bits(y)
return math.Float64frombits(f(bx, by))
}
}
示例7: test64
func test64(a, b float64) {
abits := math.Float64bits(a)
bbits := math.Float64bits(b)
if abits != bbits {
panic(fmt.Sprintf("%016x != %016x\n", abits, bbits))
}
}
示例8: MarshalTo
func (m *InternalTimeSeriesSample) MarshalTo(data []byte) (int, error) {
var i int
_ = i
var l int
_ = l
data[i] = 0x8
i++
i = encodeVarintInternal(data, i, uint64(m.Offset))
data[i] = 0x30
i++
i = encodeVarintInternal(data, i, uint64(m.Count))
data[i] = 0x39
i++
i = encodeFixed64Internal(data, i, uint64(math.Float64bits(float64(m.Sum))))
if m.Max != nil {
data[i] = 0x41
i++
i = encodeFixed64Internal(data, i, uint64(math.Float64bits(float64(*m.Max))))
}
if m.Min != nil {
data[i] = 0x49
i++
i = encodeFixed64Internal(data, i, uint64(math.Float64bits(float64(*m.Min))))
}
return i, nil
}
示例9: Interator
func (self PathData) Interator() NextElement {
count := 0
num_data := len(self)
return func() (PathDataType, []PathDataPoint) {
if count >= num_data {
return -1, nil
}
length := int(math.Float64bits(self[count]) >> 32)
path_type := int((math.Float64bits(self[count]) << 32) >> 32)
count += 2
var pathPoints []PathDataPoint
if length >= 2 {
length--
pathPoints = make([]PathDataPoint, length)
for index := range pathPoints {
pathPoints[index].x = self[count]
pathPoints[index].y = self[count+1]
}
count += (length * 2)
} else {
pathPoints = []PathDataPoint{}
}
return PathDataType(path_type), pathPoints
}
}
示例10: testcmp
func testcmp(t *testing.T, f, g float64) {
hcmp, hisnan := hwcmp(f, g)
scmp, sisnan := Fcmp64(math.Float64bits(f), math.Float64bits(g))
if int32(hcmp) != scmp || hisnan != sisnan {
err(t, "cmp(%g, %g) = sw %v, %v, hw %v, %v\n", f, g, scmp, sisnan, hcmp, hisnan)
}
}
示例11: write
func (p *PlayerPositionLook) write(ww io.Writer) (err error) {
var tmp [8]byte
tmp0 := math.Float64bits(p.X)
tmp[0] = byte(tmp0 >> 56)
tmp[1] = byte(tmp0 >> 48)
tmp[2] = byte(tmp0 >> 40)
tmp[3] = byte(tmp0 >> 32)
tmp[4] = byte(tmp0 >> 24)
tmp[5] = byte(tmp0 >> 16)
tmp[6] = byte(tmp0 >> 8)
tmp[7] = byte(tmp0 >> 0)
if _, err = ww.Write(tmp[:8]); err != nil {
return
}
tmp1 := math.Float64bits(p.Y)
tmp[0] = byte(tmp1 >> 56)
tmp[1] = byte(tmp1 >> 48)
tmp[2] = byte(tmp1 >> 40)
tmp[3] = byte(tmp1 >> 32)
tmp[4] = byte(tmp1 >> 24)
tmp[5] = byte(tmp1 >> 16)
tmp[6] = byte(tmp1 >> 8)
tmp[7] = byte(tmp1 >> 0)
if _, err = ww.Write(tmp[:8]); err != nil {
return
}
tmp2 := math.Float64bits(p.Z)
tmp[0] = byte(tmp2 >> 56)
tmp[1] = byte(tmp2 >> 48)
tmp[2] = byte(tmp2 >> 40)
tmp[3] = byte(tmp2 >> 32)
tmp[4] = byte(tmp2 >> 24)
tmp[5] = byte(tmp2 >> 16)
tmp[6] = byte(tmp2 >> 8)
tmp[7] = byte(tmp2 >> 0)
if _, err = ww.Write(tmp[:8]); err != nil {
return
}
tmp3 := math.Float32bits(p.Yaw)
tmp[0] = byte(tmp3 >> 24)
tmp[1] = byte(tmp3 >> 16)
tmp[2] = byte(tmp3 >> 8)
tmp[3] = byte(tmp3 >> 0)
if _, err = ww.Write(tmp[:4]); err != nil {
return
}
tmp4 := math.Float32bits(p.Pitch)
tmp[0] = byte(tmp4 >> 24)
tmp[1] = byte(tmp4 >> 16)
tmp[2] = byte(tmp4 >> 8)
tmp[3] = byte(tmp4 >> 0)
if _, err = ww.Write(tmp[:4]); err != nil {
return
}
if err = WriteBool(ww, p.OnGround); err != nil {
return
}
return
}
示例12: AppendComplex128
// AppendComplex128 appends a complex128 to the slice as a MessagePack extension
func AppendComplex128(b []byte, c complex128) []byte {
o, n := ensure(b, Complex128Size)
o[n] = mfixext16
o[n+1] = Complex128Extension
big.PutUint64(o[n+2:], math.Float64bits(real(c)))
big.PutUint64(o[n+10:], math.Float64bits(imag(c)))
return o
}
示例13: writeByteSortableFloat
func writeByteSortableFloat(b []byte, f float64) {
if math.Signbit(f) {
binary.BigEndian.PutUint64(b, math.Float64bits(f))
for i, v := range b[:8] {
b[i] = v ^ 255
}
} else {
binary.BigEndian.PutUint64(b, math.Float64bits(-f))
}
}
示例14: SameF64Approx
func SameF64Approx(str string, c, native, absTol, relTol float64) {
if math.IsNaN(c) && math.IsNaN(native) {
return
}
if !floats.EqualWithinAbsOrRel(c, native, absTol, relTol) {
cb := math.Float64bits(c)
nb := math.Float64bits(native)
same := floats.EqualWithinAbsOrRel(c, native, absTol, relTol)
panic(fmt.Sprintf("Case %s: Float64 mismatch. c = %v, native = %v\n cb: %v, nb: %v\n%v,%v,%v", str, c, native, cb, nb, same, absTol, relTol))
}
}
示例15: complex128Encoder
func complex128Encoder(enc *encoder, p unsafe.Pointer) error {
bs := enc.buf[:8]
v := (*complex128)(p)
enc.order.PutUint64(bs, math.Float64bits(real(*v)))
if _, err := enc.Write(bs); err != nil {
return err
}
enc.order.PutUint64(bs, math.Float64bits(imag(*v)))
_, err := enc.Write(bs)
return err
}