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.

alice.tuprolog.PrologActionFixture
enter evaluable '+'(7, 35).
check value 42
enter evaluable '+'(0, 3+11).
check value 14
enter evaluable '+'(0, 3.2+11).
check value 14.2
enter evaluable '+'(77, N).
check exception instantiation_error
enter evaluable '+'(foo, 77).
check exception type_error(number, foo)
enter evaluable '-'(7).
check value -7
enter evaluable '-'(3-11).
check value 8
enter evaluable '-'(3.2-11).
check value 7.8
enter evaluable '-'(N).
check exception instantiation_error
enter evaluable '-'(foo).
check exception type_error(number, foo)
enter evaluable '-'(7, 35).
check value -28
enter evaluable '-'(20, 3+11).
check value 6
enter evaluable '-'(0, 3.2+11).
check value -14.2
enter evaluable '-'(77, N).
check exception instantiation_error
enter evaluable '-'(foo, 77).
check exception type_error(number, foo)
enter evaluable '*'(7, 35).
check value 245
enter evaluable '*'(0, 3+11).
check value 0
enter evaluable '*'(1.5, 3.2+11).
check value 21.299999999999997
enter evaluable '*'(77, N).
check exception instantiation_error
enter evaluable '*'(foo, 77).
check exception type_error(number, foo)
enter evaluable '/'(7, 35).
check value 0
enter evaluable '/'(7.0, 35).
check value 0.2
enter evaluable '/'(140, 3+11).
check value 10
enter evaluable '/'(20.164, 3.2+11).
check value 1.4200000000000002
enter evaluable '/'(7, -3).
check value
enter evaluable '/'(-7, 3).
check value
enter evaluable '/'(77, N).
check exception instantiation_error
enter evaluable '/'(foo, 77).
check exception type_error(number, foo)
enter evaluable '/'(3, 0).
check exception evaluation_error(zero_divisor)
enter evaluable mod(7, 3).
check value 1
enter evaluable mod(0, 3+11).
check value 0
enter evaluable mod(7, -2).
check value -1
enter evaluable mod(77, N).
check exception instantiation_error
enter evaluable mod(foo, 77).
check exception type_error(number, foo)
enter evaluable mod(7.5, 2).
check exception type_error(integer, 7.5)
enter evaluable mod(7, 0).
check exception evaluation_error(zero_division)
enter evaluable floor(7.4).
check value 7
enter evaluable floor(-0.4).
check value -1
enter evaluable round(7.5).
check value 8
enter evaluable round(7.6).
check value 8
enter evaluable round(-0.6).
check value -1
enter evaluable round(N).
check exception instantiation_error
enter evaluable ceiling(-0.5).
check value 0
enter evaluable truncate(-0.5).
check value 0
enter evaluable truncate(foo).
check exception type_error(number, foo)
enter evaluable float(7).
check value 7.0
enter evaluable float(7.3).
check value 7.3
enter evaluable float(5 / 3).
check value 1.0
enter evaluable float(N).
check exception instantiation_error
enter evaluable float(foo).
check exception type_error(number, foo)
enter evaluable abs(7).
check value 7
enter evaluable abs(3-11).
check value 8
enter evaluable abs(3.2-11.0).
check value 7.8
enter evaluable abs(N).
check exception instantiation_error
enter evaluable abs(foo).
check exception type_error(number, foo)

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.

fit.ActionFixture
start alice.tuprolog.EngineFixture

Then, ask the engine to solve a query, and check for the exception thrown.

alice.tuprolog.PrologActionFixture
enter query current_prolog_flag(max_integer, MI), X is '+'(MI, 1).
check hasSolution true
check exception evaluation_error(int_overflow)
enter query current_prolog_flag(max_integer, MI), X is '-'('+'(MI, 1), 1).
check hasSolution true
check exception evaluation_error(int_overflow)
enter query current_prolog_flag(max_integer, MI), X is '*'(MI, 2).
check hasSolution true
check exception evaluation_error(int_overflow)
enter query current_prolog_flag(max_integer, MI), R is float(MI) * 2, X is floor(R).
check hasSolution true
check exception evaluation_error(int_overflow)

Run the tests!


The results of the tests for Simple arithmetic functors are as follows:

fit.Summary