github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/math/unsafe.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package math 6 7 import "unsafe" 8 9 // Float32bits returns the IEEE 754 binary representation of f, 10 // with the sign bit of f and the result in the same bit position. 11 // Float32bits(Float32frombits(x)) == x. 12 func Float32bits(f float32) uint32 { return *(*uint32)(unsafe.Pointer(&f)) } 13 14 // Float32frombits returns the floating-point number corresponding 15 // to the IEEE 754 binary representation b, with the sign bit of b 16 // and the result in the same bit position. 17 // Float32frombits(Float32bits(x)) == x. 18 func Float32frombits(b uint32) float32 { return *(*float32)(unsafe.Pointer(&b)) } 19 20 // Float64bits returns the IEEE 754 binary representation of f, 21 // with the sign bit of f and the result in the same bit position, 22 // and Float64bits(Float64frombits(x)) == x. 23 func Float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) } 24 25 // Float64frombits returns the floating-point number corresponding 26 // to the IEEE 754 binary representation b, with the sign bit of b 27 // and the result in the same bit position. 28 // Float64frombits(Float64bits(x)) == x. 29 func Float64frombits(b uint64) float64 { return *(*float64)(unsafe.Pointer(&b)) }