[m-rev.] for review: fix possible integer overflow in binary?search

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Dec 22 17:49:05 AEDT 2014



On Mon, 22 Dec 2014 14:37:00 +0800, Sebastian Godelet <sebastian.godelet+github at gmail.com> wrote:
> Being still rather unfamiliar with the Mercury internals,
> if implementing unsigned integer arithmetic is hard

Implementing unsigned arithmetic is not hard. Adding a new builtin type
for unsigned integers is what is hard. Every place in the whole Mercury
implementation (runtime, library, compiler, debugger, profilers) that
handles integers would either need to be generalized to handle unsigned
integers as well as the current signed ones, or would need to have
specialized code for handling unsigned integers added to it. Individually,
each place is probably easy to update; it is the sheer number of places
that is daunting.

> how about
> the unsigned right shift operator as Java has it (>>>), as Java is also
> lacking unsigned integers, that really helps when doing bitwise
> operations, since that way signed integers can be treated as unsigned
> integers for that particular operation.

I thought about that. But (a) anyone who really wants this operation
can already get it via foreign code, as you did; and (b) if we publically
provided such a predicate, people would ask for a full blown unsigned
integer type, which (as I said above) is hard to provide.

Zoltan.




More information about the reviews mailing list