[m-users.] Too Slow

Matthias G├╝demann matthias.guedemann at googlemail.com
Tue May 12 03:19:46 AEST 2015


Hi Peter,

thanks for your comments. I have now simplified the C code as you
suggested.

> To avoid truncation, you might have to use the mp_*_long_long
> functions.  You can check long long is at least as wide as MR_Integer,
> at compile-time, with:

> :- pragma foreign_code("C", " MR_STATIC_ASSERT(mp_int, sizeof(unsigned
> long long) >= sizeof(MR_Integer)); ").

ok, I use mp_get_long_long now

> mp_init/4 contains a mp_set_int call.

> There is a problem with:


> abs(min_int) will overflow silently or crash the program.

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,
too?

,----
| abs(Num, Abs) :-
|     ( Num < 0 ->
|         Abs = 0 - Num
|     ;
|         Abs = Num
|     ).
`----

This results in 0 for min_int.

Best regards,
Matthias



More information about the users mailing list