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
|
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);
|
#if HAVE_SNPRINTF
|
||||||
mpz_set_ui(new, n>>32);
|
sprintf(tmp,256,"%llu",n);
|
||||||
mpz_mul_2exp(new, new, 32);
|
|
||||||
mpz_add_ui(new, new, (UInt)n);
|
|
||||||
return(Yap_MkBigIntTerm(new));
|
|
||||||
#else
|
#else
|
||||||
return(MkFloatTerm(n));
|
sprintf(tmp,"%llu",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
|
||||||
|
Reference in New Issue
Block a user