本文整理汇总了Golang中math.Float32bits函数的典型用法代码示例。如果您正苦于以下问题:Golang Float32bits函数的具体用法?Golang Float32bits怎么用?Golang Float32bits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Float32bits函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMemsetAsync
func TestMemsetAsync(t *testing.T) {
N := int64(32 * 1024)
host1 := make([]float32, N)
for i := range host1 {
host1[i] = float32(i)
}
host2 := make([]float32, N)
dev1 := MemAlloc(int64(4 * N))
MemcpyHtoD(dev1, (unsafe.Pointer(&host1[0])), 4*N)
str := StreamCreate()
MemsetD32Async(dev1, math.Float32bits(42), N, str)
MemsetD32Async(dev1, math.Float32bits(21), N/2, str)
MemcpyDtoH((unsafe.Pointer(&host2[0])), dev1, 4*N)
str.Synchronize()
(&str).Destroy()
for i := 0; i < len(host2)/2; i++ {
if host2[i] != 21 {
t.Fail()
}
}
for i := len(host2) / 2; i < len(host2); i++ {
if host2[i] != 42 {
t.Fail()
}
}
dev1.Free()
}
示例2: test32
func test32(a, b float32) {
abits := math.Float32bits(a)
bbits := math.Float32bits(b)
if abits != bbits {
panic(fmt.Sprintf("%08x != %08x\n", abits, bbits))
}
}
示例3: MarshalTo
func (m *GPSMetadata) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if m.Time != 0 {
dAtA[i] = 0x8
i++
i = encodeVarintGateway(dAtA, i, uint64(m.Time))
}
if m.Latitude != 0 {
dAtA[i] = 0x15
i++
i = encodeFixed32Gateway(dAtA, i, uint32(math.Float32bits(float32(m.Latitude))))
}
if m.Longitude != 0 {
dAtA[i] = 0x1d
i++
i = encodeFixed32Gateway(dAtA, i, uint32(math.Float32bits(float32(m.Longitude))))
}
if m.Altitude != 0 {
dAtA[i] = 0x20
i++
i = encodeVarintGateway(dAtA, i, uint64(m.Altitude))
}
return i, nil
}
示例4: WriteComplex64LE
func WriteComplex64LE(w io.Writer, c complex64) error {
b := make([]byte, 8)
// little-endian
re := math.Float32bits(real(c))
for i := 0; i < 4; i++ {
b[i] = byte(re & 255)
re = re >> 8
}
im := math.Float32bits(imag(c))
for i := 4; i < 8; i++ {
b[i] = byte(im & 255)
im = im >> 8
}
n, err := w.Write(b)
if n != 8 {
return errors.New(fmt.Sprintf(
"Too few bytes written: %d, %s", n, err.Error()))
}
return nil
}
示例5: 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
}
示例6: TestFloat32SpecialCases
func TestFloat32SpecialCases(t *testing.T) {
//switch runtime.GOARCH {
//case "cs", "java":
// return
//}
for _, input := range float64inputs {
if strings.HasPrefix(input, "long:") {
if testing.Short() {
continue
}
input = input[len("long:"):]
}
r, ok := new(Rat).SetString(input)
if !ok {
t.Errorf("Rat.SetString(%q) failed", input)
continue
}
f, exact := r.Float32()
// 1. Check string -> Rat -> float32 conversions are
// consistent with strconv.ParseFloat.
// Skip this check if the input uses "a/b" rational syntax.
if !strings.Contains(input, "/") {
e64, _ := strconv.ParseFloat(input, 32)
e := float32(e64)
// Careful: negative Rats too small for
// float64 become -0, but Rat obviously cannot
// preserve the sign from SetString("-0").
switch {
case math.Float32bits(e) == math.Float32bits(f):
// Ok: bitwise equal.
case f == 0 && r.Num().BitLen() == 0:
// Ok: Rat(0) is equivalent to both +/- float64(0).
default:
t.Errorf("strconv.ParseFloat(%q) = %g (%b), want %g (%b); delta = %g", input, e, e, f, f, f-e)
}
}
if !isFinite(float64(f)) {
continue
}
// 2. Check f is best approximation to r.
if !checkIsBestApprox32(t, f, r) {
// Append context information.
t.Errorf("(input was %q)", input)
}
// 3. Check f->R->f roundtrip is non-lossy.
checkNonLossyRoundtrip32(t, f)
// 4. Check exactness using slow algorithm.
if wasExact := new(Rat).SetFloat64(float64(f)).Cmp(r) == 0; wasExact != exact {
t.Errorf("Rat.SetString(%q).Float32().exact = %t, want %t", input, exact, wasExact)
}
}
}
示例7: complex64Encoder
func complex64Encoder(enc *encoder, v reflect.Value) error {
bs := enc.buf[:8]
x := v.Complex()
enc.order.PutUint32(bs, math.Float32bits(float32(real(x))))
enc.order.PutUint32(bs[4:], math.Float32bits(float32(imag(x))))
_, err := enc.Write(bs)
return err
}
示例8: complex64Encoder
func complex64Encoder(enc *encoder, p unsafe.Pointer) error {
bs := enc.buf[:8]
v := (*complex64)(p)
enc.order.PutUint32(bs, math.Float32bits(real(*v)))
enc.order.PutUint32(bs[4:], math.Float32bits(imag(*v)))
_, err := enc.Write(bs)
return err
}
示例9: AppendComplex64
// AppendComplex64 appends a complex64 to the slice as a MessagePack extension
func AppendComplex64(b []byte, c complex64) []byte {
o, n := ensure(b, Complex64Size)
o[n] = mfixext8
o[n+1] = Complex64Extension
big.PutUint32(o[n+2:], math.Float32bits(real(c)))
big.PutUint32(o[n+6:], math.Float32bits(imag(c)))
return o
}
示例10: PolygonOffset
func (ctx *context) PolygonOffset(factor, units float32) {
ctx.enqueue(call{
args: fnargs{
fn: glfnPolygonOffset,
a0: uintptr(math.Float32bits(factor)),
a1: uintptr(math.Float32bits(units)),
},
})
}
示例11: DepthRangef
func (ctx *context) DepthRangef(n, f float32) {
ctx.enqueue(call{
args: fnargs{
fn: glfnDepthRangef,
a0: uintptr(math.Float32bits(n)),
a1: uintptr(math.Float32bits(f)),
},
})
}
示例12: PolygonOffset
func (ctx *context) PolygonOffset(factor, units float32) {
ctx.enqueue(call{
args: C.struct_fnargs{
fn: C.glfnPolygonOffset,
a0: C.uintptr_t(math.Float32bits(factor)),
a1: C.uintptr_t(math.Float32bits(units)),
},
})
}
示例13: DepthRangef
func (ctx *context) DepthRangef(n, f float32) {
ctx.enqueue(call{
args: C.struct_fnargs{
fn: C.glfnDepthRangef,
a0: C.uintptr_t(math.Float32bits(n)),
a1: C.uintptr_t(math.Float32bits(f)),
},
})
}
示例14: Uniform2f
func (ctx *context) Uniform2f(dst Uniform, v0, v1 float32) {
ctx.enqueue(call{
args: C.struct_fnargs{
fn: C.glfnUniform2f,
a0: dst.c(),
a1: C.uintptr_t(math.Float32bits(v0)),
a2: C.uintptr_t(math.Float32bits(v1)),
},
})
}
示例15: Uniform2f
func (ctx *context) Uniform2f(dst Uniform, v0, v1 float32) {
ctx.enqueue(call{
args: fnargs{
fn: glfnUniform2f,
a0: dst.c(),
a1: uintptr(math.Float32bits(v0)),
a2: uintptr(math.Float32bits(v1)),
},
})
}