diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-06-13 19:07:13 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-06-13 19:07:13 (GMT) |
commit | 505f963287b050bd46871d4659cebc65986ca5ac (patch) | |
tree | 853ad3262ab07f7c5755e76b8154f36f24608014 /libtommath/bn_mp_set_double.c | |
parent | 689987ea924a8fded1801777c1a14ab1205fa826 (diff) | |
download | tcl-505f963287b050bd46871d4659cebc65986ca5ac.zip tcl-505f963287b050bd46871d4659cebc65986ca5ac.tar.gz tcl-505f963287b050bd46871d4659cebc65986ca5ac.tar.bz2 |
Update to latest libtommath's "develop" branch. On the way to 1.2.0
Diffstat (limited to 'libtommath/bn_mp_set_double.c')
-rw-r--r-- | libtommath/bn_mp_set_double.c | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/libtommath/bn_mp_set_double.c b/libtommath/bn_mp_set_double.c index c96a3b3..a42fc70 100644 --- a/libtommath/bn_mp_set_double.c +++ b/libtommath/bn_mp_set_double.c @@ -1,47 +1,36 @@ #include "tommath_private.h" #ifdef BN_MP_SET_DOUBLE_C -/* LibTomMath, multiple-precision integer library -- Tom St Denis - * - * LibTomMath is a library that provides multiple-precision - * integer arithmetic as well as number theoretic functionality. - * - * The library was designed directly after the MPI library by - * Michael Fromberger but has been written from scratch with - * additional optimizations in place. - * - * SPDX-License-Identifier: Unlicense - */ +/* LibTomMath, multiple-precision integer library -- Tom St Denis */ +/* SPDX-License-Identifier: Unlicense */ #if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) -int mp_set_double(mp_int *a, double b) +mp_err mp_set_double(mp_int *a, double b) { uint64_t frac; - int exp, res; + int exp; + mp_err err; union { double dbl; uint64_t bits; } cast; cast.dbl = b; - exp = (int)((unsigned)(cast.bits >> 52) & 0x7FFU); - frac = (cast.bits & ((1ULL << 52) - 1ULL)) | (1ULL << 52); + exp = (int)((unsigned)(cast.bits >> 52) & 0x7FFu); + frac = (cast.bits & ((1uLL << 52) - 1uLL)) | (1uLL << 52); if (exp == 0x7FF) { /* +-inf, NaN */ return MP_VAL; } exp -= 1023 + 52; - res = mp_set_long_long(a, frac); - if (res != MP_OKAY) { - return res; - } + mp_set_u64(a, frac); - res = (exp < 0) ? mp_div_2d(a, -exp, a, NULL) : mp_mul_2d(a, exp, a); - if (res != MP_OKAY) { - return res; + err = (exp < 0) ? mp_div_2d(a, -exp, a, NULL) : mp_mul_2d(a, exp, a); + if (err != MP_OKAY) { + return err; } - if (((cast.bits >> 63) != 0ULL) && !IS_ZERO(a)) { + if (((cast.bits >> 63) != 0uLL) && !MP_IS_ZERO(a)) { a->sign = MP_NEG; } @@ -56,7 +45,3 @@ int mp_set_double(mp_int *a, double b) # endif #endif #endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ |