Files
mercury/tests/hard_coded/func_exp.m
Julien Fischer 97735d9630 Do not allow std_util.pow/3 with negative values.
library/std_util.m:
    Make std_util.pow/3 throw an exception if it is called with a negative
    integer as its second argument.

tests/hard_coded/Mmakefile:
tests/hard_coded/func_exp.{m,exp}:
    Add a test of pow/3.

NEWS:
    Announce the above change.
2023-01-11 17:10:00 +11:00

53 lines
1.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
:- module func_exp.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module list.
:- import_module std_util.
:- import_module string.
%---------------------------------------------------------------------------%
main(!IO) :-
do_test(-1, 1, !IO),
do_test(0, 1, !IO),
do_test(1, 1, !IO),
do_test(10, 1, !IO).
%---------------------------------------------------------------------------%
:- pred do_test(int::in, int::in, io::di, io::uo) is cc_multi.
do_test(N, X, !IO) :-
io.format("pow(double, %d, %d) = ", [i(N), i(X)], !IO),
( try []
Result = std_util.pow(double, N, X)
then
io.print_line(Result, !IO)
catch_any S ->
io.print_line(S, !IO)
).
%---------------------------------------------------------------------------%
:- func double(int) = int.
double(X) = 2 * X.
%---------------------------------------------------------------------------%
:- end_module func_exp.
%---------------------------------------------------------------------------%