Simple arithmetic functors

The basic arithmetic functors are defined as part of the evaluable functors which shall be implemented by a standard-conforming Prolog processor. Each evaluable functor corresponds to one or more operations according to the types of the values which are obtained by evaluating the argument(s) of the functor.

The following list identifies the simple arithmetic functors defined as part of the standard:

Note that the symbols between parentheses are infix predefined operators.

The following list identifies the functors actually exercised by this test:

Example tests

Let's start with some simple tests verifying the value of single expressions.

First of all, let's start an appropriate fixture.

fit.ActionFixture
start alice.tuprolog.EvaluationFixture

Then, ask the engine to evaluate an expression and verify the result.

Evaluable value(String evaluable)
'+'(7, 35). 42
'+'(0, 3+11). 14
'+'(0, 3.2+11). 14.2
'-'(7). -7
'-'(3-11). 8
'-'(3.2-11). 7.8
'-'(7, 35). -28
'-'(20, 3+11). 6
'-'(0, 3.2+11). -14.2
'*'(7, 35). 245
'*'(0, 3+11). 0
'*'(1.5, 3.2+11). 21.299999999999997
'/'(7, 35). 0
'/'(7.0, 35). 0.2
'/'(140, 3+11). 10
'/'(20.164, 3.2+11). 1.4200000000000002
mod(7, 3). 1
mod(0, 3+11). 0
mod(7, -2). -1
floor(7.4). 7
floor(-0.4). -1
round(7.5). 8
round(7.6). 8
round(-0.6). -1
ceiling(-0.5). 0
truncate(-0.5). 0
float(7). 7.0
float(7.3). 7.3
float(5 / 3). 1.0
abs(7). 7
abs(3-11). 8
abs(3.2-11.0). 7.8

The remaining tests cover the cases when an error or exception is thrown by the engine while solving a query.

First of all, let's start an appropriate fixture containing an engine.

Goal Theory success(String goal) Type Of Error
current_prolog_flag(max_integer, MI), X is '+'(MI, 1). null true
current_prolog_flag(max_integer, MI), X is '-'('+'(MI, 1), 1). null true
current_prolog_flag(max_integer, MI), X is '*'(MI, 2). null true
current_prolog_flag(max_integer, MI), R is float(MI) * 2, X is floor(R). null true