mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-25 04:55:04 +02:00
WIP - new version of libtommath
This commit is contained in:
parent
2e9a5bd9c2
commit
b2b10ca729
2 changed files with 11 additions and 22 deletions
|
@ -1378,7 +1378,7 @@ void **vpbuffer_add(void **buf, int *len, int i, void *obj);
|
||||||
void vpbuffer_free(void **buf);
|
void vpbuffer_free(void **buf);
|
||||||
|
|
||||||
/* Bignum utility functions */
|
/* Bignum utility functions */
|
||||||
double mp_get_double(mp_int *a);
|
double mp_get_double(const mp_int *a);
|
||||||
int Cyc_bignum_cmp(bn_cmp_type type, object x, int tx, object y, int ty);
|
int Cyc_bignum_cmp(bn_cmp_type type, object x, int tx, object y, int ty);
|
||||||
void Cyc_int2bignum(int n, mp_int *bn);
|
void Cyc_int2bignum(int n, mp_int *bn);
|
||||||
|
|
||||||
|
|
29
runtime.c
29
runtime.c
|
@ -1422,28 +1422,17 @@ object Cyc_num_cmp_va_list(void *data, int argc,
|
||||||
* Code is from: https://github.com/libtom/libtommath/issues/3
|
* Code is from: https://github.com/libtom/libtommath/issues/3
|
||||||
*/
|
*/
|
||||||
#define PRECISION 53
|
#define PRECISION 53
|
||||||
double mp_get_double(mp_int *a)
|
double mp_get_double(const mp_int *a)
|
||||||
{
|
{
|
||||||
static const int NEED_DIGITS = (PRECISION + 2 * DIGIT_BIT - 2) / DIGIT_BIT;
|
int i;
|
||||||
static const double DIGIT_MULTI = (mp_digit)1 << DIGIT_BIT;
|
double d = 0.0, fac = 1.0;
|
||||||
|
for (i = 0; i < DIGIT_BIT; ++i) {
|
||||||
int i, limit;
|
fac *= 2.0;
|
||||||
double d = 0.0;
|
|
||||||
|
|
||||||
mp_clamp(a);
|
|
||||||
i = USED(a);
|
|
||||||
limit = i <= NEED_DIGITS ? 0 : i - NEED_DIGITS;
|
|
||||||
|
|
||||||
while (i-- > limit) {
|
|
||||||
d += DIGIT(a, i);
|
|
||||||
d *= DIGIT_MULTI;
|
|
||||||
}
|
}
|
||||||
|
for (i = a->used; i --> 0;) {
|
||||||
if(SIGN(a) == MP_NEG)
|
d = (d * fac) + (double)DIGIT(a, i);
|
||||||
d *= -1.0;
|
}
|
||||||
|
return (a->sign == MP_NEG) ? -d : d;
|
||||||
d *= pow(2.0, i * DIGIT_BIT);
|
|
||||||
return d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert a bignum back to fixnum if possible
|
// Convert a bignum back to fixnum if possible
|
||||||
|
|
Loading…
Add table
Reference in a new issue