Sha256: ee861bf35c8d531c6e2a50433663d50233be355947e41afd4a3b974e5b738c91

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 KB

Contents

:- module arith_int.
:- interface.

:- import_module io.
:- pred main(io::di, io::uo) is det.

:- implementation.
:- import_module int, list, string.

main(!IO) :-
    io.command_line_arguments(Args, !IO),
    ( if
        Args = [AStr, BStr],
        string.to_int(AStr, A),
        string.to_int(BStr, B)
      then
        io.format("A + B = %d\n", [i(A + B)], !IO),
        io.format("A - B = %d\n", [i(A - B)], !IO),
        io.format("A * B = %d\n", [i(A * B)], !IO),

        % Division: round towards zero.
        %
        io.format("A / B = %d\n", [i(A / B)], !IO),

        % Division: round towards minus infinity.
        %
        io.format("A div B = %d\n", [i(A div B)], !IO), 
    
        % Modulus: X mod Y = X - (X div Y) * Y.
        %
        io.format("A mod B = %d\n", [i(A mod B)], !IO),

        % Remainder: X rem Y = X - (X / Y) * Y.
        %
        io.format("A rem B = %d\n", [i(A rem B)], !IO),

        % Exponentiation is done using the function int.pow/2.
        %
        io.format("A `pow` B = %d\n", [i(A `pow` B)], !IO)
      else
        io.set_exit_status(1, !IO)
    ).

Version data entries

10 entries across 7 versions & 1 rubygems

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