blob: 5ae67420f4dc029dfb0bc816378520ef42a09d2d [file] [log] [blame]
Russ Cox488ca3c2009-10-15 23:09:22 -07001// 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
5package math
6
7import "unsafe"
8
9// Float32bits returns the IEEE 754 binary representation of f.
Robert Griesemera3d10452009-12-15 15:35:38 -080010func Float32bits(f float32) uint32 { return *(*uint32)(unsafe.Pointer(&f)) }
Russ Cox488ca3c2009-10-15 23:09:22 -070011
12// Float32frombits returns the floating point number corresponding
13// to the IEEE 754 binary representation b.
Robert Griesemera3d10452009-12-15 15:35:38 -080014func Float32frombits(b uint32) float32 { return *(*float32)(unsafe.Pointer(&b)) }
Russ Cox488ca3c2009-10-15 23:09:22 -070015
16// Float64bits returns the IEEE 754 binary representation of f.
Robert Griesemera3d10452009-12-15 15:35:38 -080017func Float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) }
Russ Cox488ca3c2009-10-15 23:09:22 -070018
19// Float64frombits returns the floating point number corresponding
20// the IEEE 754 binary representation b.
Robert Griesemera3d10452009-12-15 15:35:38 -080021func Float64frombits(b uint64) float64 { return *(*float64)(unsafe.Pointer(&b)) }