Sha256: 95f4f009d9ed9554f29f96a2324f0e80f5ff1d582dcb9a41e69fe165610b17fd

Contents?: true

Size: 524 Bytes

Versions: 10

Compression:

Stored size: 524 Bytes

Contents

Integer quotient (`//`) rounds towards 0.

Remainder (`rem`) matches the sign of its first operand.



print_expression_and_result(M, N, Operator) :-
    Expression =.. [Operator, M, N],
    Result is Expression,
    format('~w ~8|is ~d~n', [Expression, Result]).

arithmetic_integer :-
    read(M),
    read(N),
    maplist( print_expression_and_result(M, N), [+,-,*,//,rem,^] ).



Use thus:


?- arithmetic_integer.
|: 5.
|: 7.
5+7     is 12
5-7     is -2
5*7     is 35
5//7    is 0
5 rem 7 is 5
5^7     is 78125
true.

Version data entries

10 entries across 7 versions & 1 rubygems

Version Path
zettacode-0.1.7 files.zettacode/arithmetic.integer/prolog.txt
zettacode-0.1.6 files.zettacode/arithmetic.integer/prolog.txt
zettacode-0.1.6 files.zettacode2/arithmetic.integer/prolog.txt
zettacode-0.1.5 files.zettacode/arithmetic.integer/prolog.txt
zettacode-0.1.5 files.zettacode2/arithmetic.integer/prolog.txt
zettacode-0.1.4 files.zettacode/arithmetic.integer/prolog.txt
zettacode-0.1.4 files.zettacode2/arithmetic.integer/prolog.txt
zettacode-0.1.3 files.zettacode/arithmetic.integer/prolog.txt
zettacode-0.1.2 files.zettacode/arithmetic.integer/prolog.txt
zettacode-0.1.1 zettacode.files/arithmetic.integer/prolog.txt