Russ Cox | 488ca3c | 2009-10-15 23:09:22 -0700 | [diff] [blame] | 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. |
Robert Griesemer | a3d1045 | 2009-12-15 15:35:38 -0800 | [diff] [blame] | 10 | func Float32bits(f float32) uint32 { return *(*uint32)(unsafe.Pointer(&f)) } |
Russ Cox | 488ca3c | 2009-10-15 23:09:22 -0700 | [diff] [blame] | 11 | |
| 12 | // Float32frombits returns the floating point number corresponding |
| 13 | // to the IEEE 754 binary representation b. |
Robert Griesemer | a3d1045 | 2009-12-15 15:35:38 -0800 | [diff] [blame] | 14 | func Float32frombits(b uint32) float32 { return *(*float32)(unsafe.Pointer(&b)) } |
Russ Cox | 488ca3c | 2009-10-15 23:09:22 -0700 | [diff] [blame] | 15 | |
| 16 | // Float64bits returns the IEEE 754 binary representation of f. |
Robert Griesemer | a3d1045 | 2009-12-15 15:35:38 -0800 | [diff] [blame] | 17 | func Float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) } |
Russ Cox | 488ca3c | 2009-10-15 23:09:22 -0700 | [diff] [blame] | 18 | |
| 19 | // Float64frombits returns the floating point number corresponding |
| 20 | // the IEEE 754 binary representation b. |
Robert Griesemer | a3d1045 | 2009-12-15 15:35:38 -0800 | [diff] [blame] | 21 | func Float64frombits(b uint64) float64 { return *(*float64)(unsafe.Pointer(&b)) } |