fix converting long long to BigInt/Int
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1457 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
5680364300
commit
e021bef90d
23
C/bignum.c
23
C/bignum.c
@ -222,23 +222,22 @@ Yap_BigIntOfTerm(Term t)
|
||||
Term
|
||||
Yap_MkULLIntTerm(YAP_ULONG_LONG n)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
if (n != (UInt)n) {
|
||||
#if USE_GMP
|
||||
/* try to scan it as a bignum */
|
||||
#ifdef __GNUC__ && USE_GMP
|
||||
MP_INT *new = Yap_PreAllocBigNum();
|
||||
char tmp[256];
|
||||
|
||||
mpz_init(new);
|
||||
mpz_set_ui(new, n>>32);
|
||||
mpz_mul_2exp(new, new, 32);
|
||||
mpz_add_ui(new, new, (UInt)n);
|
||||
return(Yap_MkBigIntTerm(new));
|
||||
#if HAVE_SNPRINTF
|
||||
sprintf(tmp,256,"%llu",n);
|
||||
#else
|
||||
return(MkFloatTerm(n));
|
||||
sprintf(tmp,"%llu",n);
|
||||
#endif
|
||||
} else {
|
||||
return MkIntegerTerm(n);
|
||||
/* try to scan it as a bignum */
|
||||
mpz_init(new);
|
||||
mpz_set_str(new, tmp, 10);
|
||||
if (mpz_fits_slong_p(new)) {
|
||||
return MkIntegerTerm(mpz_get_si(new));
|
||||
}
|
||||
return Yap_MkBigIntTerm(new);
|
||||
#else
|
||||
return MkIntegerTerm(n);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user