core.checkedint added to druntime

bearophile via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Wed Jun 18 02:43:07 PDT 2014


Walter Bright:

> https://github.com/D-Programming-Language/druntime/pull/839

Why aren't functions with ubyte/byte/short/ushort arguments 
included?

--------------

Here Lionello Lunesu has suggested a __traits(valueRange, 
<expression>) for built-in values:
http://forum.dlang.org/thread/lnrc8l$1254$1@digitalmars.com

Once such trait is working on checkedint values, can this help 
the compiler remove some useless tests and increase the 
performance of checked ints?


> it can be used to implement multi-precision integer arithmetic 
> types.

It looks very useful for the "small value optimization" for 
BigIntegers, to not allocate on the heap when the numbers are 
small, and switch to the heap allocation when they grow.

If you use such improved bigintegers to write code that is not 
supposed to overflow the range of normal integers, you obtain 
code that is only moderately slower than using checkedints, but 
it also gives the correct results if some overflow has occurred 
:-)

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list