libtommath/mp_get_double.c

19 lines
433 B
C
Raw Normal View History

2018-09-10 16:51:26 +00:00
#include "tommath_private.h"
#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
}
2018-12-28 08:34:02 +00:00
return (a->sign == MP_NEG) ? -d : d;
2018-09-10 16:51:26 +00:00
}
#endif