2018-09-10 16:51:26 +00:00
|
|
|
#include "tommath_private.h"
|
2019-10-19 14:24:39 +00:00
|
|
|
#ifdef MP_GET_DOUBLE_C
|
2019-04-07 13:29:11 +00:00
|
|
|
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
|
|
|
/* SPDX-License-Identifier: Unlicense */
|
2018-09-10 16:51:26 +00:00
|
|
|
|
|
|
|
double mp_get_double(const mp_int *a)
|
|
|
|
{
|
|
|
|
int i;
|
2018-11-28 09:42:11 +00:00
|
|
|
double d = 0.0, fac = 1.0;
|
2019-04-13 06:46:57 +00:00
|
|
|
for (i = 0; i < MP_DIGIT_BIT; ++i) {
|
2018-11-28 09:42:11 +00:00
|
|
|
fac *= 2.0;
|
2018-09-10 16:51:26 +00:00
|
|
|
}
|
2018-12-28 07:51:46 +00:00
|
|
|
for (i = a->used; i --> 0;) {
|
2019-03-26 10:34:06 +00:00
|
|
|
d = (d * fac) + (double)a->dp[i];
|
2018-09-10 16:51:26 +00:00
|
|
|
}
|
2019-11-09 19:23:03 +00:00
|
|
|
return mp_isneg(a) ? -d : d;
|
2018-09-10 16:51:26 +00:00
|
|
|
}
|
|
|
|
#endif
|