2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog @(#)eval.h 1.2
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: eval.h *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: arithmetical functions info *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/* C library used to implement floating point functions */
|
2002-06-25 17:13:56 +01:00
|
|
|
#if HAVE_MATH_H
|
2001-04-09 20:54:03 +01:00
|
|
|
#include <math.h>
|
2002-06-25 17:13:56 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
#if HAVE_IEEEFP_H
|
|
|
|
#include <ieeefp.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_LIMITS_H
|
|
|
|
#include <limits.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LONG_MAX
|
|
|
|
#define Int_MAX LONG_MAX
|
|
|
|
#else
|
|
|
|
#define Int_MAX ((Int)((~((CELL)0))>>1))
|
|
|
|
#endif
|
|
|
|
#ifdef LONG_MIN
|
|
|
|
#define Int_MIN LONG_MIN
|
|
|
|
#else
|
2001-10-30 16:42:05 +00:00
|
|
|
#define Int_MIN (-Int_MAX-(CELL)1)
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef union arith_ret {
|
|
|
|
Int Int;
|
|
|
|
Float dbl;
|
|
|
|
#ifdef USE_GMP
|
2006-01-02 02:16:19 +00:00
|
|
|
mpz_t big;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
} *arith_retptr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
#define RINT(v) return(MkIntegerTerm(v))
|
|
|
|
#define RFLOAT(v) return(MkFloatTerm(v))
|
2002-11-18 18:18:05 +00:00
|
|
|
#define RBIG(v) return(Yap_MkBigIntTerm(v))
|
|
|
|
#define RBIG_FL(v) return(Yap_MkBigIntTerm((MP_INT *)(Int)v))
|
2001-04-09 20:54:03 +01:00
|
|
|
#define RERROR() return(MkIntTerm(0))
|
|
|
|
*/
|
|
|
|
|
|
|
|
Functor STD_PROTO(EvalArg,(Term,arith_retptr));
|
|
|
|
|
|
|
|
/* Needed to handle numbers:
|
|
|
|
these two macros are fundamental in the integer/float conversions */
|
|
|
|
|
|
|
|
#ifdef C_PROLOG
|
|
|
|
#define FlIsInt(X) ( (X) == (Int)(X) && IntInBnd((X)) )
|
|
|
|
#else
|
|
|
|
#define FlIsInt(X) ( FALSE )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef M_WILLIAMS
|
|
|
|
#define MkEvalFl(X) MkFloatTerm(X)
|
|
|
|
#else
|
|
|
|
#define MkEvalFl(X) ( FlIsInt(X) ? MkIntTerm((Int)(X)) : MkFloatTerm(X) )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Macros used by some of the eval functions */
|
|
|
|
#define REvalInt(I) { eval_int = (I); return(FInt); }
|
|
|
|
#define REvalFl(F) { eval_flt = (F); return(FFloat); }
|
|
|
|
#define REvalError() { return(FError); }
|
|
|
|
|
|
|
|
/* this macro, dependent on the particular implementation
|
|
|
|
is used to interface the arguments into the C libraries */
|
|
|
|
#if MPW
|
|
|
|
#define FL(X) ((extended)(X))
|
|
|
|
#else
|
|
|
|
#define FL(X) ((double)(X))
|
|
|
|
#endif
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
extern yap_error_number Yap_matherror;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
void STD_PROTO(Yap_InitConstExps,(void));
|
|
|
|
void STD_PROTO(Yap_InitUnaryExps,(void));
|
|
|
|
void STD_PROTO(Yap_InitBinaryExps,(void));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
int STD_PROTO(Yap_ReInitConstExps,(void));
|
|
|
|
int STD_PROTO(Yap_ReInitUnaryExps,(void));
|
|
|
|
int STD_PROTO(Yap_ReInitBinaryExps,(void));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
blob_type STD_PROTO(Yap_Eval,(Term, union arith_ret *));
|