[m-users.] Too Slow
novalazy at gmail.com
Tue May 12 17:56:24 AEST 2015
On Mon, 11 May 2015 18:19:46 +0100, matthias.guedemann at googlemail.com (Matthias Güdemann) wrote:
> ok, I chose the lazy solution to convert to string and then use
> from_string to get the correct value. But isn't this a problem in int.m,
> | abs(Num, Abs) :-
> | ( Num < 0 ->
> | Abs = 0 - Num
> | ;
> | Abs = Num
> | ).
Right. int.m says "The behaviour of a computation for which overflow
occurs is undefined." abs(min_int) silently returns a negative value
for you; on another system it can (and does) crash instead.
If int.m checked for overflow then abs(min_int) would throw an
exception, so you still need to avoid it.
This definition of mp_int does not convert to string:
mp_int(N) = Res :-
( N < 0 ->
( N = min_int ->
% Avoid `-min_int' as it overflows.
mp_init(-(min_int + 1), M),
Res = -(M + one)
Res = -M
mp_init/3 still has a call to mp_set_int that should be
More information about the users