Refactor bigints, add int and float conv functions
Added functions to convert from/to ints/floats. Floats are converted according to basic Steele&White algorithm (without speedup).
This commit is contained in:
31
src/Util.c
31
src/Util.c
@@ -23,6 +23,37 @@ union I64
|
||||
};
|
||||
|
||||
|
||||
union F64
|
||||
{
|
||||
double f;
|
||||
uint64_t u64;
|
||||
};
|
||||
|
||||
|
||||
int BH_ClassifyDouble(double value)
|
||||
{
|
||||
union F64 tmp;
|
||||
uint64_t fract;
|
||||
int exp, negative;
|
||||
|
||||
tmp.f = value;
|
||||
exp = (tmp.u64 >> 52) & 0x7FF;
|
||||
fract = (tmp.u64 & (((uint64_t)1 << 52) - 1));
|
||||
negative = (tmp.u64 >> 63) ? (BH_FP_NEGATIVE) : (0);
|
||||
|
||||
if (exp == 0 && fract == 0)
|
||||
return BH_FP_ZERO | negative;
|
||||
|
||||
if (exp == 2047 && fract == 0)
|
||||
return BH_FP_INFINITE | negative;
|
||||
|
||||
if (exp == 2047 && fract)
|
||||
return BH_FP_NAN;
|
||||
|
||||
return BH_FP_NORMAL | negative;
|
||||
}
|
||||
|
||||
|
||||
uint16_t BH_Read16LEu(const char *buffer)
|
||||
{
|
||||
union I16 tmp;
|
||||
|
||||
Reference in New Issue
Block a user