diff --git a/bn_mp_get_double.c b/bn_mp_get_double.c index 542993d..8ce314f 100644 --- a/bn_mp_get_double.c +++ b/bn_mp_get_double.c @@ -16,14 +16,14 @@ double mp_get_double(const mp_int *a) { int i; - double d = 0, fac = 1; + double d = 0.0, fac = 1.0; for (i = 0; i < DIGIT_BIT; ++i) { - fac *= 2; + fac *= 2.0; } for (i = USED(a); i --> 0;) { - d = d * fac + (double)DIGIT(a, i); + d = (d * fac) + (double)DIGIT(a, i); } - return mp_isneg(a) ? -d : d; + return (mp_isneg(a) != MP_NO) ? -d : d; } #endif diff --git a/bn_mp_set_double.c b/bn_mp_set_double.c index 0a5f771..0e230c7 100644 --- a/bn_mp_set_double.c +++ b/bn_mp_set_double.c @@ -14,7 +14,7 @@ */ #if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) -int mp_set_double(mp_int *a, double d) +int mp_set_double(mp_int *a, double b) { uint64_t frac; int exp, res; @@ -22,10 +22,10 @@ int mp_set_double(mp_int *a, double d) double dbl; uint64_t bits; } cast; - cast.dbl = d; + cast.dbl = b; - exp = (int)(cast.bits >> 52) & 0x7FF; - frac = (cast.bits & ((1ULL << 52) - 1)) | (1ULL << 52); + exp = (unsigned)(cast.bits >> 52) & 0x7FFU; + frac = (cast.bits & ((1ULL << 52) - 1ULL)) | (1ULL << 52); if (exp == 0x7FF) { /* +-inf, NaN */ return MP_VAL; @@ -37,8 +37,8 @@ int mp_set_double(mp_int *a, double d) return res; } - res = exp < 0 ? mp_div_2d(a, -exp, a, 0) : mp_mul_2d(a, exp, a); - if ((cast.bits >> 63) && !mp_iszero(a)) { + res = (exp < 0) ? mp_div_2d(a, -exp, a, NULL) : mp_mul_2d(a, exp, a); + if (((cast.bits >> 63) != 0ULL) && (mp_iszero(a) == MP_NO)) { SIGN(a) = MP_NEG; }