mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
fix gu_encode_double
This commit is contained in:
@@ -45,9 +45,9 @@ gu_decode_double(uint64_t u)
|
|||||||
GU_INTERNAL uint64_t
|
GU_INTERNAL uint64_t
|
||||||
gu_encode_double(double d)
|
gu_encode_double(double d)
|
||||||
{
|
{
|
||||||
int sign = (d < 0) ? 1 : 0;
|
int sign = signbit(d) > 0;
|
||||||
int rawexp;
|
unsigned rawexp;
|
||||||
double mantissa;
|
uint64_t mantissa;
|
||||||
|
|
||||||
switch (fpclassify(d)) {
|
switch (fpclassify(d)) {
|
||||||
case FP_NAN:
|
case FP_NAN:
|
||||||
@@ -58,14 +58,19 @@ gu_encode_double(double d)
|
|||||||
rawexp = 0x7ff;
|
rawexp = 0x7ff;
|
||||||
mantissa = 0;
|
mantissa = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default: {
|
||||||
mantissa = frexp(d, &rawexp);
|
int exp;
|
||||||
rawexp += 1075;
|
mantissa = (uint64_t) scalbn(frexp(d, &exp), 53);
|
||||||
|
mantissa &= ~ (1ULL << 52);
|
||||||
|
exp -= 53;
|
||||||
|
|
||||||
|
rawexp = exp + 1075;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t u = (((uint64_t) sign) << 63) |
|
uint64_t u = (((uint64_t) sign) << 63) |
|
||||||
((((uint64_t) rawexp) << 52) & 0x7ff) |
|
(((uint64_t) rawexp & 0x7ff) << 52) |
|
||||||
((uint64_t) mantissa);
|
mantissa;
|
||||||
|
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user