/************************************************************************* * * * YAP Prolog * * * * Yap Prolog was developed at NCCUP - Universidade do Porto * * * * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * * * ************************************************************************** * * * File: eval.c * * Last rev: * * mods: * * comments: arithmetical expression evaluation * * * *************************************************************************/ #ifdef SCCS static char SccsId[] = "%W% %G%"; #endif /** @file arith0.c */ //! @{ /** @defgroup arithmetic_operators Arithmetic Functions @ingroup arithmetic YAP implements several arithmetic functions, they are defined as fields in three enumerations, such that there is one enumeration per each different arity: - #arith0_op defines constants and arity 0 arithmetic functions @copydoc #arith0_op - #arith1_op defines single argument arithmetic functions @copydoc #arith1_op - #arith2_op defines binary arithmetic functions @copydoc #arith2_op Arithmetic expressions in YAP may use the following operators: - pi [ISO]
@anchor pi_0 An approximation to the value of pi, that is, the ratio of a circle's circumference to its diameter. - e
@anchor e_0 Euler's number, the base of the natural logarithms. - epsilon
@anchor epsilon_0 The difference between the float `1.0` and the next largest floating point number. - inf
@anchor inf_0 Infinity according to the IEEE Floating-Point standard. Note that evaluating this term will generate a domain error in the `iso` language mode. Note also that YAP supports `+inf` and `-inf` - nan (not a number)
@anchor nan_0 Not-a-number according to the IEEE Floating-Point standard. Note that evaluating this term will generate a domain error in the `iso` language mode. - random
@anchor random_0 A "random" floating point number between 0 and 1. - cputime
@anchor cputime_0 CPU time since YAP was invoked, in seconds. - heapused
@anchor heapused_0 Heap (data-base) space used, in bytes. - local
@anchor local_0 Local stack in use, in bytes - $b
@anchor b_0 current choicepoint - $env
@anchor env_0 Environment - $tr
@anchor tr_0 Trail in use - $free_stack
@anchor free_stack_0 Amount of free stack space, that is, free space between global and local stacks. - global
@anchor global_0
Global stack in use, in bytes.
*
*/
#include "Yap.h"
#include "Yatom.h"
#include "YapHeap.h"
#include "YapEval.h"
static Term
eval0(Int fi) {
CACHE_REGS
arith0_op fop = fi;
switch (fop) {
case op_pi:
{
RFLOAT(PI);
}
case op_e:
{
RFLOAT(M_E);
}
case op_epsilon:
{
RFLOAT(DBL_EPSILON);
}
case op_inf:
{
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, "evaluating infinity");
P = (yamop *)FAILCODE;
RERROR();
#else
if (isoLanguageFlag()) {/* iso */
Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, "evaluating infinity");
P = (yamop *)FAILCODE;
RERROR();
} else {
RFLOAT(INFINITY);
}
#endif
}
case op_nan:
{
#ifdef _MSC_VER /* Microsoft's Visual C++ Compi