Bug in ^^

Brett Brett at gmail.com
Tue Sep 17 16:50:29 UTC 2019


On Tuesday, 17 September 2019 at 16:16:44 UTC, bachmeier wrote:
> On Tuesday, 17 September 2019 at 13:48:02 UTC, Brett wrote:
>
>> it's shorthand for writing out the long version, it shouldn't 
>> silently wrap, If I write out the long version it craps out so 
>> why not the computation itself?
>
> I think you should be using 
> https://dlang.org/phobos/std_experimental_checkedint.html 
> rather than getting into the weeds of the best language design 
> choices long ago. My thought is that it's relatively easy to 
> work with long if that's what I want:
>
> 10L^^16
> long(10)^^16
>
> I have to be explicit, but it's not Java levels of verbosity. 
> Using long doesn't solve overflow problems. A different default 
> would be better in your example, but it's not clear to me why 
> that would always be better - the proper default would be 
> checkedint.

Wrong:
import std.stdio;
enum x = 100000000000000000;
enum y = 10^^17;

void main()
{
     ulong xx = x;
     ulong yy = y;
     writeln(x);
     writeln(y);
     writeln(xx);
     writeln(yy);
}

100000000000000000
1569325056
100000000000000000
1569325056

I gave code to prove that I was right, why is it so difficult for 
people to accept? All I see is people trying to justify the 
compilers current behavior rather than think for themselves and 
realize something wrong!

This not a difficult issue.




More information about the Digitalmars-d mailing list