+static word wputexp(word w, int exp)
+{
+ return ((w & ~(word)0177) | ((exp < 0) ? 0100 | (-exp) : exp));
+}
+
+static int wmanti(word w)
+{
+ return ((w >> 8) & ((1 << 28) - 1));
+}
+
+static double wtofloat(word w)
+{
+ double x = wmanti(w);
+ return ldexp(x, wexp(w) - 28);
+}
+
+static int float_in_range(double x)
+{
+ x = fabs(x);
+ return (x <= ldexp((1 << 28) - 1, 63 - 28));
+}
+
+static word wfromfloat(double x, int normalized)
+{
+ word w = 0;
+ if (x < 0)
+ {
+ w |= SIGN_MASK;
+ x = -x;
+ }
+ int exp;
+ double m = frexp(x, &exp);
+ word mm = (word) ldexp(m, 28);
+ if (exp > 63)
+ assert(0);
+ else if (exp < -63)
+ {
+ if (normalized || exp < -91)
+ mm=0, exp=0;
+ else
+ {
+ mm >>= -exp - 63;
+ exp = -63;
+ }
+ }
+ w |= mm << 8;
+ if (exp < 0)
+ {
+ w |= 0100;
+ exp = -exp;
+ }
+ w |= exp;
+ return w;
+}
+