unsafe.go 859 B

12345678910111213141516171819202122
  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. package math
  5. import "unsafe"
  6. // Float32bits returns the IEEE 754 binary representation of f.
  7. func Float32bits(f float32) uint32 { return *(*uint32)(unsafe.Pointer(&f)) }
  8. // Float32frombits returns the floating point number corresponding
  9. // to the IEEE 754 binary representation b.
  10. func Float32frombits(b uint32) float32 { return *(*float32)(unsafe.Pointer(&b)) }
  11. // Float64bits returns the IEEE 754 binary representation of f.
  12. func Float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) }
  13. // Float64frombits returns the floating point number corresponding
  14. // the IEEE 754 binary representation b.
  15. func Float64frombits(b uint64) float64 { return *(*float64)(unsafe.Pointer(&b)) }