{
inst->reachability <<= 1;
inst->reachability |= !!reachable;
- inst->reachability &= ~(-1 << SOURCE_REACH_BITS);
+ inst->reachability %= 1U << SOURCE_REACH_BITS;
if (inst->reachability_size < SOURCE_REACH_BITS)
inst->reachability_size++;
assert(0);
return 0;
};
- return buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
+ return (uint32_t)buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
}
return 0;
}
double
UTI_FloatNetworkToHost(Float f)
{
- int32_t exp, coef, x;
+ int32_t exp, coef;
+ uint32_t x;
x = ntohl(f.f);
+
exp = (x >> FLOAT_COEF_BITS) - FLOAT_COEF_BITS;
- coef = x << FLOAT_EXP_BITS >> FLOAT_EXP_BITS;
+ if (exp >= 1 << (FLOAT_EXP_BITS - 1))
+ exp -= 1 << FLOAT_EXP_BITS;
+
+ coef = x % (1U << FLOAT_COEF_BITS);
+ if (coef >= 1 << (FLOAT_COEF_BITS - 1))
+ coef -= 1 << FLOAT_COEF_BITS;
+
return coef * pow(2.0, exp);
}
if (neg)
coef = (uint32_t)-coef << FLOAT_EXP_BITS >> FLOAT_EXP_BITS;
- f.f = htonl(exp << FLOAT_COEF_BITS | coef);
+ f.f = htonl((uint32_t)exp << FLOAT_COEF_BITS | coef);
return f;
}