Time to move std.experimental.checkedint to std.checkedint ?

Paul Backus snarwin at gmail.com
Mon Mar 29 21:05:08 UTC 2021


On Monday, 29 March 2021 at 20:00:03 UTC, Walter Bright wrote:
> D's integral promotion rules (bytes and shorts are promoted to 
> ints before doing arithmetic) get rid of the bulk of likely 
> overflows. (It's ironic that the integral promotion rules are 
> much maligned and considered a mistake, I don't share that 
> opinion, and this is one of the reasons why.)

Well...sometimes they do:

     auto result = int.max + int.max;
     writeln(typeof(result).stringof); // int
     writeln(result); // -2

The main issue with D's integer promotion rules is that they're 
inconsistent. Sometimes truncating the result of an expression 
requires an explicit cast, and sometimes it doesn't.


More information about the Digitalmars-d mailing list