aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/runtime.c')
-rw-r--r--src/runtime/runtime.c28
1 files changed, 28 insertions, 0 deletions
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;