Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > d1f06a5336fd6bf4a381b72b8d2b5ce1 > files > 164

gprolog-1.2.16-3mdk.ppc.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14">
<TITLE>
 Arithmetic
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="manual028.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual023.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="manual030.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#66dbff"><DIV ALIGN=center><TABLE>
<TR><TD><FONT SIZE=4><B><A NAME="htoc87">7.6</A></B></FONT></TD>
<TD WIDTH="100%" ALIGN=center><FONT SIZE=4><B>Arithmetic</B></FONT></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><UL>
<LI><A HREF="manual029.html#toc60"> Evaluation of an arithmetic expression</A>
<LI><A HREF="manual029.html#toc61"> <TT>(is)/2</TT> - evaluate expression</A>
<LI><A HREF="manual029.html#toc62"> <TT>(=:=)/2</TT> - arithmetic equal,
 <TT>(=\=)/2</TT> - arithmetic not equal,<BR>
<TT>(&lt;)/2</TT> - arithmetic less than,
 <TT>(=&lt;)/2</TT> - arithmetic less than or equal to,<BR>
<TT>(&gt;)/2</TT> - arithmetic greater than,
 <TT>(&gt;=)/2</TT> - arithmetic greater than or equal to</A>
</UL>
<BR>
<A NAME="toc60"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc88">7.6.1</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B>Evaluation of an arithmetic expression</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Evaluation-of-an-arithmetic-expression"></A>
An arithmetic expression is a Prolog term built from numbers,
variables, and functors (or operators) that represent arithmetic functions.
When an expression is evaluated each variable must be bound to a
non-variable expression. An expression evaluates to a number, which may be
an integer or a floating point number. The following table details the
components of an arithmetic expression, how they are evaluated, the types
expected/returned and if they are ISO or an extension:<BR>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD VALIGN=top ALIGN=left NOWRAP>Expression</TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>Result = <I>eval</I>(Expression)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>Signature</TD>
<TD VALIGN=top ALIGN=center NOWRAP>ISO</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP>Variable</TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>must be bound to a non-variable expression <TT>E</TT>. 
<BR>
The result is <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; IF</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP>integer number</TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>this number</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>I -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP>floating point number</TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>this number</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>F -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>+ E</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; IF</TD>
<TD VALIGN=top ALIGN=center NOWRAP>N</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>- E</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>- <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; IF</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>inc(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E</TT>) + 1</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; IF</TD>
<TD VALIGN=top ALIGN=center NOWRAP>N</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>dec(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E</TT>) - 1</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; IF</TD>
<TD VALIGN=top ALIGN=center NOWRAP>N</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 + E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) + <I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF, IF -&gt; IF</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 - E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) - <I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF, IF -&gt; IF</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 * E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) * <I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF, IF -&gt; IF</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 / E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) / <I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF, IF -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 // E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>rnd</I>(<I>eval</I>(<TT>E1</TT>) /
<I>eval</I>(<TT>E2</TT>))</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>I, I -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 rem E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) -
(<I>rnd</I>(<I>eval</I>(<TT>E1</TT>) /
<I>eval</I>(<TT>E2</TT>))*<I>eval</I>(<TT>E2</TT>))</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>I, I -&gt;
I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 mod E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) - (
lfloor<I>eval</I>(<TT>E1</TT>) / <I>eval</I>(<TT>E2</TT>)rfloor
*<I>eval</I>(<TT>E2</TT>))</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>I, I -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 /\ E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) bitwise_and
<I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>I, I -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 \/ E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) bitwise_or
<I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>I, I -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 ^ E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) bitwise_xor
<I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>I, I -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>N</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>\ E</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>bitwise_not <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>I -&gt;
I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 &lt;&lt; E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) integer_shift_left
<I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>I, I -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 &gt;&gt; E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) integer_shift_right
<I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>I, I -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>abs(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>absolute value of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF
-&gt; IF</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>sign(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>sign of <I>eval</I>(<TT>E</TT>) (-1 if &lt; 0, 0 if = 0,
+1 if &gt; 0)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; IF</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>min(E1,E2)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>minimal value between <I>eval</I>(<TT>E1</TT>) and
<I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF, IF -&gt; ?</TD>
<TD VALIGN=top ALIGN=center NOWRAP>N</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>max(E1,E2)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>maximal value between <I>eval</I>(<TT>E1</TT>) and
<I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF, IF -&gt; ?</TD>
<TD VALIGN=top ALIGN=center NOWRAP>N</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>E1 ** E2</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>eval</I>(<TT>E1</TT>) raised to the power of
<I>eval</I>(<TT>E2</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF, IF -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>sqrt(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>square root of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF
-&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>atan(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>arc tangent of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF
-&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>cos(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>cosine of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>acos(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>arc cosine of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>N</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>sin(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>sine of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>asin(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>arc sine of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>N</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>exp(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left><I>e</I> raised to the power of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>log(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>natural logarithms of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF
-&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>float(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>the floating point number equal to
<I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>IF -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>ceiling(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>rounds <I>eval</I>(<TT>E</TT>) upward to the
nearest integer</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>F -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>floor(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>rounds <I>eval</I>(<TT>E</TT>) downward to the
nearest integer</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>F -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>round(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>rounds <I>eval</I>(<TT>E</TT>) to the nearest integer</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>F -&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>truncate(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>the integer value of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>F
-&gt; I</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>float_fractional_part(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>the float equal to the fractional part
of <I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>F -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>float_integer_part(E)</TT></TD>
<TD VALIGN=top ALIGN=left><DIV ALIGN=left>the float equal to the integer part of
<I>eval</I>(<TT>E</TT>)</DIV></TD>
<TD VALIGN=top ALIGN=center NOWRAP>F -&gt; F</TD>
<TD VALIGN=top ALIGN=center NOWRAP>Y</TD>
</TR></TABLE><BR>
The meaning of the signature field is as follows:
<UL><LI>I -&gt; I: unary function, the operand must be an integer and
the result is an integer.<BR>
<BR>
<LI>F -&gt; F: unary function, the operand must be a floating
point number and the result is a floating point number.<BR>
<BR>
<LI>F -&gt; I: unary function, the operand must be a floating
point number and the result is an integer.<BR>
<BR>
<LI>IF -&gt; F: unary function, the operand can be an integer or a
floating point number and the result is a floating point number.<BR>
<BR>
<LI>IF -&gt; IF: unary function, the operand can be an integer or
a floating point number and the result has the same type as the operand.<BR>
<BR>
<LI>I, I -&gt; I: binary function: each operand must be an integer
and the result is an integer.<BR>
<BR>
<LI>IF, IF -&gt; IF: binary function: each operand can be an
integer or a floating point number and the result is a floating point number
if at least one operand is a floating point number, an integer otherwise.<BR>
<BR>
<LI>IF, IF -&gt; ?: binary function: each operand can be an
integer or a floating point number and the result has the same type as the
selected operand. This is used for <TT>min</TT> and <TT>max</TT>. Note that
in case of equality between an integer and a floating point number the
result is an integer.</UL>
<TT>is</TT>, <TT>+</TT>, <TT>-</TT>, <TT>*</TT>, <TT>//</TT>, <TT>/</TT>,
<TT>rem</TT>, and <TT>mod</TT> are predefined infix operators. <TT>+</TT>
and <TT>-</TT> are predefined prefix operators (section&nbsp;<A HREF="manual037.html#op/3:(Term-input/output)">7.14.10</A>).<BR>
<BR>
<B>Integer division rounding function</B>: the integer division rounding
function <TT><I>rnd</I>(X)</TT> rounds the floating point number
<TT>X</TT> to an integer. There are two possible definitions (depending on
the target machine) for this function which differ on negative numbers:
<UL><LI><TT><I>rnd</I>(X)</TT> = integer part of <TT>X</TT>, e.g.
<TT><I>rnd</I>(-1.5)</TT> = <TT>-1</TT> (round toward 0)<BR>
<BR>
<LI><TT><I>rnd</I>(X)</TT> = lfloor<TT>X</TT>rfloor, e.g.
<TT><I>rnd</I>(-1.5)</TT> = <TT>-2</TT> (round toward -oo)</UL>
The definition of this function determines the precise definition of the
integer division <TT>(//)/2</TT> and of the integer remainder
<TT>(rem)/2</TT>. Rounding toward zero is the most common case. In any case
it is possible to test the value (<TT>toward_zero</TT> or <TT>down</TT>) of
the <TT>integer_rounding_function</TT> Prolog flag to determine which
function being used (section&nbsp;<A HREF="manual045.html#set-prolog-flag/2">7.22.1</A>).<BR>
<BR>
<B>Fast mathematical mode</B>: in order to speed-up integer computations,
the GNU Prolog compiler can generate faster code when invoked with the
<TT>--fast-math</TT> option (section&nbsp;<A HREF="manual008.html#Using-the-compiler">3.4.3</A>). In this mode only
integer operations are allowed and a variable in an expression must be bound
at evaluation time to an integer. No type checking is done. <BR>
<BR>
<B>Errors</B><BR>
<TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left>a sub-expression <TT>E</TT> is a variable</TD>
<TD VALIGN=top ALIGN=center NOWRAP>&nbsp;&nbsp;</TD>
<TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left>a sub-expression <TT>E</TT> is neither a number nor an evaluable
functor</TD>
<TD VALIGN=top ALIGN=center NOWRAP>&nbsp;&nbsp;</TD>
<TD VALIGN=top ALIGN=left><TT>type_error(evaluable, E)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left>a sub-expression <TT>E</TT> is a floating point number while an
integer is expected</TD>
<TD VALIGN=top ALIGN=center NOWRAP>&nbsp;&nbsp;</TD>
<TD VALIGN=top ALIGN=left><TT>type_error(integer, E)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left>a sub-expression <TT>E</TT> is an integer while a floating point
number is expected</TD>
<TD VALIGN=top ALIGN=center NOWRAP>&nbsp;&nbsp;</TD>
<TD VALIGN=top ALIGN=left><TT>type_error(float, E)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left>a division by zero occurs</TD>
<TD VALIGN=top ALIGN=center NOWRAP>&nbsp;&nbsp;</TD>
<TD VALIGN=top ALIGN=left><TT>evaluation_error(zero_divisor)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR></TABLE><BR>
<B>Portability</B><BR>
<BR>
Refer to the above table to determine which evaluable functors are ISO
and which are GNU Prolog extensions. For efficiency reasons, GNU
Prolog does not detect the following ISO arithmetic errors:
<TT>float_overflow</TT>,
<TT>int_overflow, int_underflow</TT>, and <TT>undefined</TT>.<BR>
<BR>
<A NAME="toc61"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc89">7.6.2</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B><TT>(is)/2</TT> - evaluate expression</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
 <BR>
<B>Templates</B>
<DL COMPACT=compact><DT><DD><TT>
is(?nonvar, +evaluable)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>Result is Expression</TT> succeeds if <TT>Result</TT> can be
unified with <I>eval</I>(<TT>Expression</TT>). Refer to the
evaluation of an arithmetic expression for the definition of the
<I>eval</I> function
(section&nbsp;<A HREF="#Evaluation-of-an-arithmetic-expression">7.6.1</A>).<BR>
<BR>
<TT>is</TT> is a predefined infix operator (section&nbsp;<A HREF="manual037.html#op/3:(Term-input/output)">7.14.10</A>).<BR>
<BR>
<B>Errors</B><BR>
<BR>
Refer to the evaluation of an arithmetic expression for possible errors
(section&nbsp;<A HREF="#Evaluation-of-an-arithmetic-expression">7.6.1</A>).<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO predicate.<BR>
<BR>
<A NAME="toc62"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE>
<TR><TD><B><A NAME="htoc90">7.6.3</A></B></TD>
<TD WIDTH="100%" ALIGN=center><B><TT>(=:=)/2</TT> - arithmetic equal,
 <TT>(=\=)/2</TT> - arithmetic not equal,<BR>
<TT>(&lt;)/2</TT> - arithmetic less than,
 <TT>(=&lt;)/2</TT> - arithmetic less than or equal to,<BR>
<TT>(&gt;)/2</TT> - arithmetic greater than,
 <TT>(&gt;=)/2</TT> - arithmetic greater than or equal to</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="(=:=)/2"></A> 
 
 
 
 
 
 <BR>
<B>Templates</B>
<DL COMPACT=compact><DT><DD><TT>
=:=(+evaluable, +evaluable)<BR>
=\=(+evaluable, +evaluable)<BR>
&lt;(+evaluable, +evaluable)<BR>
=&lt;(+evaluable, +evaluable)<BR>
&gt;(+evaluable, +evaluable)<BR>
&gt;=(+evaluable, +evaluable)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>Expr1 =:= Expr2</TT> succeeds if <I>eval</I>(<TT>Expr1</TT>) =
<I>eval</I>(<TT>Expr2</TT>).<BR>
<BR>
<TT>Expr1 =\= Expr2</TT> succeeds if <I>eval</I>(<TT>Expr1</TT>)
!= <I>eval</I>(<TT>Expr2</TT>).<BR>
<BR>
<TT>Expr1 &lt; Expr2</TT> succeeds if <I>eval</I>(<TT>Expr1</TT>) &lt;
<I>eval</I>(<TT>Expr2</TT>).<BR>
<BR>
<TT>Expr1 =&lt; Expr2</TT> succeeds if <I>eval</I>(<TT>Expr1</TT>)
&lt;= <I>eval</I>(<TT>Expr2</TT>).<BR>
<BR>
<TT>Expr1 &gt; Expr2</TT> succeeds if <I>eval</I>(<TT>Expr1</TT>) &gt;
<I>eval</I>(<TT>Expr2</TT>).<BR>
<BR>
<TT>Expr1 &gt;= Expr2</TT> succeeds if <I>eval</I>(<TT>Expr1</TT>)
&gt;= <I>eval</I>(<TT>Expr2</TT>).<BR>
<BR>
Refer to the evaluation of an arithmetic expression for the definition of
the <I>eval</I> function (section&nbsp;<A HREF="#Evaluation-of-an-arithmetic-expression">7.6.1</A>).<BR>
<BR>
<TT>=:=</TT>, <TT>=\=</TT>, <TT>&lt;</TT>, <TT>=&lt;</TT>,
<TT>&gt;</TT> and <TT>&gt;=</TT> are predefined infix operators
(section&nbsp;<A HREF="manual037.html#op/3:(Term-input/output)">7.14.10</A>).<BR>
<BR>
<B>Errors</B><BR>
<BR>
Refer to the evaluation of an arithmetic expression for possible errors
(section&nbsp;<A HREF="#Evaluation-of-an-arithmetic-expression">7.6.1</A>).<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO predicates.<BR>
<BR>

<HR SIZE=2>
Copyright (C) 1999-2002 Daniel Diaz
<BR>
<BR>
Verbatim copying and distribution of this entire article is permitted in any
medium, provided this notice is preserved. <BR>
<BR>
<A HREF="index.html#copyright">More about the copyright</A>
<HR>
<A HREF="manual028.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual023.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="manual030.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>