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:
vsc 2005-11-15 02:05:49 +00:00
parent 5680364300
commit e021bef90d

View File

@ -222,25 +222,24 @@ Yap_BigIntOfTerm(Term t)
Term Term
Yap_MkULLIntTerm(YAP_ULONG_LONG n) Yap_MkULLIntTerm(YAP_ULONG_LONG n)
{ {
#ifdef __GNUC__ #ifdef __GNUC__ && USE_GMP
if (n != (UInt)n) {
#if USE_GMP
/* try to scan it as a bignum */
MP_INT *new = Yap_PreAllocBigNum(); MP_INT *new = Yap_PreAllocBigNum();
char tmp[256];
mpz_init(new);
mpz_set_ui(new, n>>32); #if HAVE_SNPRINTF
mpz_mul_2exp(new, new, 32); sprintf(tmp,256,"%llu",n);
mpz_add_ui(new, new, (UInt)n); #else
return(Yap_MkBigIntTerm(new)); sprintf(tmp,"%llu",n);
#else
return(MkFloatTerm(n));
#endif #endif
} else { /* try to scan it as a bignum */
return MkIntegerTerm(n); 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 #else
return MkIntegerTerm(n); return MkIntegerTerm(n);
#endif #endif
} }