[m-dev.] for review: big ints again
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Apr 8 19:01:26 AEST 1998
On 08-Apr-1998, Bert Thompson <aet at hydra.cs.mu.oz.au> wrote:
> Implementation of an arbitrary precision integer type and
> operations on it.
>
> library/integer.m
> test/general/bigint.m
The log message is not quite the usual format;
something like
library/integer.m:
Implementation of an arbitrary precision integer type and
operations on it.
tests/general/bigint.m:
Some test cases for library/integer.m.
would be better.
It would probably be better to name the test case integer_test.m
rather than bigint.m. This is consistent with the names used for
various other test cases, e.g. relation_test.m.
> :- func integer:'/'(integer, integer) = integer.
>
> :- func integer:'//'(integer, integer) = integer.
...
> integer:'/'(X1, X2) =
> big_quot(X1, X2).
>
> integer:'//'(X1, X2) =
> big_quot(X1, X2).
You should delete the `/' function, or change it to return `rational'
rather than `integer'.
> :- func int_to_integer(int) = integer.
> int_to_integer(D) = i(signum(D), pos_int_to_digits(AD)) :-
> int__abs(D, AD).
This function does the wrong thing for MININT.
(See, isn't code review wonderful? ;-)
> :- func signum(int) = int.
> signum(N) = SN :-
> (N < 0 ->
Please s/(N/( N/
> :- pred pos_geq_rev(list(digit), list(digit)).
> :- mode pos_geq_rev(in, in) is semidet.
> pos_geq_rev(Xs, Ys) :-
> list__reverse(Xs, RXs),
> list__reverse(Ys, RYs),
> C = big_cmp(i(1, RXs), i(1, RYs)),
> ( C = greaterthan ; C = equal).
Please s/equal)/equal )/
> :- func big_pow(integer, integer) = integer.
> big_pow(A, N) = P :-
> ( N = integer(0) ->
> P = integer(1)
> ; big_odd(N) ->
> P = A * big_pow(A, N-integer(1))
> ; % even
> P = big_sqr(big_pow(A, N/integer(2)))
> ).
You should use `//' here rather than `/'.
> :- func big_sqr(integer) = integer.
> big_sqr(A) = A * A.
>
> :- pred big_odd(integer).
> :- mode big_odd(in) is semidet.
> big_odd(N) :-
> ( N = integer(0) ->
> fail
> ;
> N = i(_S, [D|_Ds]),
> D mod 2 = 1
> ).
Isn't the explicit test for zero unnecessary?
big_odd(N) :-
N = i(_S, [D|_Ds]),
D mod 2 = 1.
I'd like to see another diff please.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list