core.checkedint

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 24 15:56:33 PDT 2016


On 6/24/2016 3:29 PM, Andrei Alexandrescu wrote:
> These functions are not supposed to be used naïvely.

They are also meant to be inspectable. I want to look at it and trivially know 
what I am getting. Deep knowledge of subtle cases in the language (and integral 
promotions satisfy that) should not be necessary *especially* for this set of 
functions. People get into enough trouble over misunderstanding whether they are 
using signed or unsigned arithmetic as it is.

I've used core.checkedint here and there, and have been well satisfied with the 
existing interface.

   int add(int x, int y, ref uint overflows);
   uint add(uint x, uint y, ref uint overflows);
   long add(long x, int y, ref uint overflows);
   ulong add(ulong x, uint y, ref uint overflows);

   ubyte i;
   uint u;
   uint overflow;
   add(i, u, overflow);

Quickly, without trying it out, tell me which one it calls. No cheating!



More information about the Digitalmars-d mailing list