interface to rationals.
This commit is contained in:
parent
53e8811077
commit
3c261305db
@ -385,6 +385,7 @@ X_API Bool STD_PROTO(YAP_IsNonVarTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsIntTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsLongIntTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsBigNumTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsRationalTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsFloatTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsDbRefTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsAtomTerm,(Term));
|
||||
@ -392,8 +393,10 @@ X_API Bool STD_PROTO(YAP_IsPairTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsApplTerm,(Term));
|
||||
X_API Term STD_PROTO(YAP_MkIntTerm,(Int));
|
||||
X_API Term STD_PROTO(YAP_MkBigNumTerm,(void *));
|
||||
X_API Term STD_PROTO(YAP_MkRationalTerm,(void *));
|
||||
X_API Int STD_PROTO(YAP_IntOfTerm,(Term));
|
||||
X_API void STD_PROTO(YAP_BigNumOfTerm,(Term, void *));
|
||||
X_API void STD_PROTO(YAP_RationalOfTerm,(Term, void *));
|
||||
X_API Term STD_PROTO(YAP_MkFloatTerm,(flt));
|
||||
X_API flt STD_PROTO(YAP_FloatOfTerm,(Term));
|
||||
X_API Term STD_PROTO(YAP_MkAtomTerm,(Atom));
|
||||
@ -601,7 +604,29 @@ X_API Bool
|
||||
YAP_IsBigNumTerm(Term t)
|
||||
{
|
||||
#if USE_GMP
|
||||
return IsBigIntTerm(t);
|
||||
CELL *pt;
|
||||
if (IsVarTerm(t))
|
||||
return FALSE;
|
||||
if (!IsBigIntTerm(t))
|
||||
return FALSE;
|
||||
pt = RepAppl(t);
|
||||
return pt[1] == BIG_INT;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
X_API Bool
|
||||
YAP_IsRationalTerm(Term t)
|
||||
{
|
||||
#if USE_GMP
|
||||
CELL *pt;
|
||||
if (IsVarTerm(t))
|
||||
return FALSE;
|
||||
if (!IsBigIntTerm(t))
|
||||
return FALSE;
|
||||
pt = RepAppl(t);
|
||||
return pt[1] == BIG_RATIONAL;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
@ -698,6 +723,33 @@ YAP_BigNumOfTerm(Term t, void *b)
|
||||
#endif /* USE_GMP */
|
||||
}
|
||||
|
||||
X_API Term
|
||||
YAP_MkRationalTerm(void *big)
|
||||
{
|
||||
#if USE_GMP
|
||||
Term I;
|
||||
BACKUP_H();
|
||||
I = Yap_MkBigRatTerm((MP_RAT *)big);
|
||||
RECOVER_H();
|
||||
return I;
|
||||
#else
|
||||
return TermNil;
|
||||
#endif /* USE_GMP */
|
||||
}
|
||||
|
||||
X_API void
|
||||
YAP_RationalOfTerm(Term t, void *b)
|
||||
{
|
||||
#if USE_GMP
|
||||
MP_RAT *br = (MP_RAT *)b;
|
||||
if (IsVarTerm(t))
|
||||
return;
|
||||
if (!IsBigIntTerm(t))
|
||||
return;
|
||||
mpq_set(br,Yap_BigRatOfTerm(t));
|
||||
#endif /* USE_GMP */
|
||||
}
|
||||
|
||||
X_API Term
|
||||
YAP_MkBlobTerm(unsigned int sz)
|
||||
{
|
||||
|
@ -103,6 +103,9 @@ extern X_API YAP_Bool PROTO(YAP_IsLongIntTerm,(YAP_Term));
|
||||
/* YAP_Bool IsBigNumTerm(YAP_Term) */
|
||||
extern X_API YAP_Bool PROTO(YAP_IsBigNumTerm,(YAP_Term));
|
||||
|
||||
/* YAP_Bool IsRationalTerm(YAP_Term) */
|
||||
extern X_API YAP_Bool PROTO(YAP_IsRationalTerm,(YAP_Term));
|
||||
|
||||
/* YAP_Bool IsFloatTerm(YAP_Term) */
|
||||
extern X_API YAP_Bool PROTO(YAP_IsFloatTerm,(YAP_Term));
|
||||
|
||||
@ -124,12 +127,18 @@ extern X_API YAP_Term PROTO(YAP_MkIntTerm,(YAP_Int));
|
||||
/* Term MkBigNumTerm(void *) */
|
||||
extern X_API YAP_Term PROTO(YAP_MkBigNumTerm,(void *));
|
||||
|
||||
/* Term MkRationalTerm(void *) */
|
||||
extern X_API YAP_Term PROTO(YAP_MkRationalTerm,(void *));
|
||||
|
||||
/* YAP_Int IntOfTerm(Term) */
|
||||
extern X_API YAP_Int PROTO(YAP_IntOfTerm,(YAP_Term));
|
||||
|
||||
/* void * BigNumOfTerm(Term) */
|
||||
extern X_API void *PROTO(YAP_BigNumOfTerm,(YAP_Term, void *));
|
||||
|
||||
/* void * RationalOfTerm(Term) */
|
||||
extern X_API void *PROTO(YAP_RationalOfTerm,(YAP_Term, void *));
|
||||
|
||||
/* Term MkFloatTerm(YAP_Float) */
|
||||
extern X_API YAP_Term PROTO(YAP_MkFloatTerm,(YAP_Float));
|
||||
|
||||
|
@ -190,6 +190,12 @@ valueExpression(term_t t, Number r ARG_LD)
|
||||
YAP_BigNumOfTerm(t0, &r->value.mpz);
|
||||
return 1;
|
||||
}
|
||||
if (YAP_IsRationalTerm(t0)) {
|
||||
r->type = V_MPQ;
|
||||
mpq_init(&r->value.mpq);
|
||||
YAP_RationalOfTerm(t0, &r->value.mpq);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user