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

tsbockman thomas.bockman at gmail.com
Tue Mar 30 01:28:55 UTC 2021


On Tuesday, 30 March 2021 at 00:02:54 UTC, H. S. Teoh wrote:
> If you want mathematical integers, you should be using 
> std.bigint or something similar instead.
>
>
>> Otherwise, the algorithm is simple:
>> 
>>     if(floor(mathResult) <= codeResult && codeResult <= 
>> ceil(mathResult))
>>         return codeResult;
>>     else
>>         signalErrorSomehow();
>
> Implementing such a scheme would introduce so much overhead 
> that it would render the `int` type essentially useless for 
> systems programming. Or for any application where performance 
> is important, for that matter.

You have a wildly exaggerated sense of the runtime performance 
cost of doing things the way I advocate if you think it is 
anywhere close to bigint.

My proposal (grossly oversimplified) is mostly just to check the 
built-in CPU overflow flags once in a while. I've actually tested 
this, and even with a library solution the overhead is low in 
most realistic scenarios, if the inliner and optimizer are 
effective. A language solution could do even better, I'm sure.


More information about the Digitalmars-d mailing list