aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-01-22 16:23:44 -0800
committerRuss Cox <rsc@golang.org>2009-01-22 16:23:44 -0800
commit1f8a40d85c3bb7a1cf3113e7ab1afdb44f6c0e4d (patch)
treeece2442553c8681e8134d2201e6201e1e429adb8 /src/runtime/runtime.c
parent8c5bc7e93adae7546b4f1520d1b20f18ebe95d88 (diff)
downloadgo-1f8a40d85c3bb7a1cf3113e7ab1afdb44f6c0e4d.tar.xz
move math routines from package sys to package math,
though they still build in src/runtime. use cgo instead of hand-written wrappers. R=r DELTA=740 (289 added, 300 deleted, 151 changed) OCL=23326 CL=23331
Diffstat (limited to 'src/runtime/runtime.c')
-rw-r--r--src/runtime/runtime.c255
1 files changed, 0 insertions, 255 deletions
diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c
index 31bd1ed868..29a67b190d 100644
--- a/src/runtime/runtime.c
+++ b/src/runtime/runtime.c
@@ -113,261 +113,6 @@ rnd(uint32 n, uint32 m)
return n;
}
-static uint64 uvnan = 0x7FF0000000000001ULL;
-static uint64 uvinf = 0x7FF0000000000000ULL;
-static uint64 uvneginf = 0xFFF0000000000000ULL;
-
-static uint32
-float32tobits(float32 f)
-{
- // 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.f = f;
- return u.i;
-}
-
-static uint64
-float64tobits(float64 f)
-{
- // The obvious cast-and-pointer code is technically
- // not valid, and gcc miscompiles it. Use a union instead.
- union {
- float64 f;
- uint64 i;
- } u;
- u.f = f;
- return u.i;
-}
-
-static float64
-float64frombits(uint64 i)
-{
- // The obvious cast-and-pointer code is technically
- // not valid, and gcc miscompiles it. Use a union instead.
- union {
- float64 f;
- uint64 i;
- } u;
- u.i = 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)
-{
- uint64 x;
-
- x = float64tobits(f);
- if(sign == 0)
- return x == uvinf || x == uvneginf;
- if(sign > 0)
- return x == uvinf;
- return x == uvneginf;
-}
-
-static float64
-NaN(void)
-{
- return float64frombits(uvnan);
-}
-
-bool
-isNaN(float64 f)
-{
- uint64 x;
-
- x = float64tobits(f);
- return ((uint32)(x>>52) & 0x7FF) == 0x7FF && !isInf(f, 0);
-}
-
-static float64
-Inf(int32 sign)
-{
- if(sign >= 0)
- return float64frombits(uvinf);
- else
- return float64frombits(uvneginf);
-}
-
-enum
-{
- MASK = 0x7ffL,
- SHIFT = 64-11-1,
- BIAS = 1022L,
-};
-
-static float64
-frexp(float64 d, int32 *ep)
-{
- uint64 x;
-
- if(d == 0) {
- *ep = 0;
- return 0;
- }
- x = float64tobits(d);
- *ep = (int32)((x >> SHIFT) & MASK) - BIAS;
- x &= ~((uint64)MASK << SHIFT);
- x |= (uint64)BIAS << SHIFT;
- return float64frombits(x);
-}
-
-static float64
-ldexp(float64 d, int32 e)
-{
- uint64 x;
-
- if(d == 0)
- return 0;
- x = float64tobits(d);
- e += (int32)(x >> SHIFT) & MASK;
- if(e <= 0)
- return 0; /* underflow */
- if(e >= MASK){ /* overflow */
- if(d < 0)
- return Inf(-1);
- return Inf(1);
- }
- x &= ~((uint64)MASK << SHIFT);
- x |= (uint64)e << SHIFT;
- return float64frombits(x);
-}
-
-static float64
-modf(float64 d, float64 *ip)
-{
- float64 dd;
- uint64 x;
- int32 e;
-
- if(d < 1) {
- if(d < 0) {
- d = modf(-d, ip);
- *ip = -*ip;
- return -d;
- }
- *ip = 0;
- return d;
- }
-
- x = float64tobits(d);
- e = (int32)((x >> SHIFT) & MASK) - BIAS;
-
- /*
- * Keep the top 11+e bits; clear the rest.
- */
- if(e <= 64-11)
- x &= ~(((uint64)1 << (64LL-11LL-e))-1);
- dd = float64frombits(x);
- *ip = dd;
- return d - dd;
-}
-
-// func Frexp(float64) (float64, int32); // break fp into exp,frac
-void
-sys·Frexp(float64 din, float64 dou, int32 iou)
-{
- dou = frexp(din, &iou);
- FLUSH(&dou);
-}
-
-//func ldexp(int32, float64) float64; // make fp from exp,frac
-void
-sys·Ldexp(float64 din, int32 ein, float64 dou)
-{
- dou = ldexp(din, ein);
- FLUSH(&dou);
-}
-
-//func modf(float64) (float64, float64); // break fp into double+double
-void
-sys·Modf(float64 din, float64 integer, float64 fraction)
-{
- fraction = modf(din, &integer);
- FLUSH(&fraction);
-}
-
-//func isinf(float64, int32 sign) bool; // test for infinity
-void
-sys·IsInf(float64 din, int32 signin, bool out)
-{
- out = isInf(din, signin);
- FLUSH(&out);
-}
-
-//func isnan(float64) bool; // test for NaN
-void
-sys·IsNaN(float64 din, bool out)
-{
- out = isNaN(din);
- FLUSH(&out);
-}
-
-//func inf(int32 sign) float64; // signed infinity
-void
-sys·Inf(int32 signin, float64 out)
-{
- out = Inf(signin);
- FLUSH(&out);
-}
-
-//func nan() float64; // NaN
-void
-sys·NaN(float64 out)
-{
- out = NaN();
- FLUSH(&out);
-}
-
-// func float32bits(float32) uint32; // raw bits of float32
-void
-sys·Float32bits(float32 din, uint32 iou)
-{
- iou = float32tobits(din);
- FLUSH(&iou);
-}
-
-// func float64bits(float64) uint64; // raw bits of float64
-void
-sys·Float64bits(float64 din, uint64 iou)
-{
- iou = float64tobits(din);
- 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;