Bug in ^^

Dominikus Dittes Scherkl dominikus.scherkl at continental-corporation.com
Tue Sep 17 14:06:26 UTC 2019


On Tuesday, 17 September 2019 at 13:48:02 UTC, Brett wrote:

> enum x = 100000000000000000;
this is of type long, because the literal is too large to be an 
int

> enum y = 10^^17;
this is of type int (the default)
the exponentiation operator (like any other operator) produces a 
result of same type as the input, so still an int.
if you want long, you should write

enum y = 10L^^17

You should have a look at the language specification.
D inherits C's bad behaviour of defaulting to int (not even uint)
and even large literals are per default signed (sigh!)

Anyway, nothing can always prevent you from overflow, or what 
should be the result of

enum z = 10L ^^ 122

automatically import bigInt from a library? And even then,
how about 1000_000_000 ^^ 1000_000_000 --> try it and throw some 
outOfMemory error?



More information about the Digitalmars-d mailing list