From 2f4d35ffb9dfc84277a1c868d71d6f89bfd19f7f Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Wed, 12 Nov 2008 11:51:34 -0800 Subject: converting uint bits back into floats R=rsc DELTA=32 (32 added, 0 deleted, 0 changed) OCL=19084 CL=19091 --- src/runtime/runtime.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/runtime/runtime.c') diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index a75a7f8cc5..c84b21092e 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -204,6 +204,19 @@ float64frombits(uint64 i) return u.f; } +static float32 +float32frombits(uint32 i) +{ + // The obvious cast-and-pointer code is technically + // not valid, and gcc miscompiles it. Use a union instead. + union { + float32 f; + uint32 i; + } u; + u.i = i; + return u.f; +} + bool isInf(float64 f, int32 sign) { @@ -387,6 +400,21 @@ sys·float64bits(float64 din, uint64 iou) FLUSH(&iou); } +// func float32frombits(uint32) float32; // raw bits to float32 +void +sys·float32frombits(uint32 uin, float32 dou) +{ + dou = float32frombits(uin); + FLUSH(&dou); +} + +// func float64frombits(uint64) float64; // raw bits to float64 +void +sys·float64frombits(uint64 uin, float64 dou) +{ + dou = float64frombits(uin); + FLUSH(&dou); +} static int32 argc; static uint8** argv; -- cgit v1.3