當前位置: 首頁>>代碼示例>>Golang>>正文


Golang math.Float32bits函數代碼示例

本文整理匯總了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()
}
開發者ID:jamesbjackson,項目名稱:cuda4,代碼行數:27,代碼來源:memory_test.go

示例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))
	}
}
開發者ID:Xiahl1990,項目名稱:go,代碼行數:7,代碼來源:issue14651.go

示例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
}
開發者ID:TheThingsNetwork,項目名稱:ttn,代碼行數:27,代碼來源:gateway.pb.go

示例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
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:25,代碼來源:binary.go

示例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
}
開發者ID:suedadam,項目名稱:steven,代碼行數:59,代碼來源:play_serverbound_proto.go

示例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)
		}
	}
}
開發者ID:joao-parana,項目名稱:tardisgo,代碼行數:59,代碼來源:rat_haxe_test.go

示例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
}
開發者ID:rainycape,項目名稱:gondola,代碼行數:8,代碼來源:encoder.go

示例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
}
開發者ID:rainycape,項目名稱:gondola,代碼行數:8,代碼來源:encoder_unsafe.go

示例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
}
開發者ID:0x20h,項目名稱:grafana,代碼行數:9,代碼來源:write_bytes.go

示例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)),
		},
	})
}
開發者ID:ych1,項目名稱:mobile,代碼行數:9,代碼來源:gl.go

示例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)),
		},
	})
}
開發者ID:ych1,項目名稱:mobile,代碼行數:9,代碼來源:gl.go

示例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)),
		},
	})
}
開發者ID:samanalysis,項目名稱:mobile,代碼行數:9,代碼來源:gl.go

示例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)),
		},
	})
}
開發者ID:samanalysis,項目名稱:mobile,代碼行數:9,代碼來源:gl.go

示例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)),
		},
	})
}
開發者ID:samanalysis,項目名稱:mobile,代碼行數:10,代碼來源:gl.go

示例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)),
		},
	})
}
開發者ID:ych1,項目名稱:mobile,代碼行數:10,代碼來源:gl.go


注:本文中的math.Float32bits函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。