Skip to content

Commit

Permalink
Casts instead of manually constructing doubles
Browse files Browse the repository at this point in the history
  • Loading branch information
gvx committed Feb 16, 2012
1 parent ec876d6 commit 31c0370
Showing 1 changed file with 2 additions and 33 deletions.
35 changes: 2 additions & 33 deletions vm/literals.c
Expand Up @@ -21,38 +21,6 @@ uint64_t ntohll(uint64_t i)
}
#endif

double unpack754(uint64_t i)
{
double result;
long long shift;

if (i == 0)
{
return 0.0;
}

result = (i & ((1LL << 52) - 1));
result /= (1LL << 52);
result += 1.0;

shift = ((i >> 52) & ((1LL << 11) - 1)) - (1 << 10) + 1;
while(shift-- > 0)
{
result *= 2.0;
}
while(++shift < 0)
{
result /= 2.0;
}

if (i >> 63)
{
result = -result;
}

return result;
}

void read_literals(FILE* f, Header* h)
{
long oldpos = ftell(f);
Expand Down Expand Up @@ -91,7 +59,8 @@ void read_literals(FILE* f, Header* h)
{
uint64_t d;
fread(&d, sizeof(d), 1, f);
t = double_to_value(unpack754(ntohll(d)));
d = ntohll(d);
t = double_to_value(*(double*)&d);
}
else //if (type == TYPE_STR || type == TYPE_IDENT)
{
Expand Down

0 comments on commit 31c0370

Please sign in to comment.