Bug in ^^

Johan Engelen j at j.nl
Tue Sep 17 17:42:47 UTC 2019

Calm down Brett :-)
People are only trying to help here, and as far as I can tell 
they fully understood what you wrote.

On Tuesday, 17 September 2019 at 17:23:06 UTC, Brett wrote:
> enum x = 100000000000000000;
> enum y = 10^^17;
> Why do you think 10^^17 and 100000000000000000
> should be different?
> First I'm told that enum's are ints

That is not what was meant. Enums are not always ints. The type 
of the initializing expression determines the type of the enum.
Numbers are by default `int`, unless it must be another type.
10 --->  is an `int`
17 --->  is an `int`
100000000000000000 --> cannot be an `int`, so is a larger type

> and so 10^17 should wrap...

10^17 is equal to  "number ^^ number". What's the first number? 
10. So that's an `int`. What's the second number? 17, also an 
`int`.  `int ^^ int` results in another `int`. Thus the type of 
the expression "10^^17" is `int` --> the enum that is initialized 
by 10^^17 will also be an `int`. The wrapping that you see is not 
that the enum is wrapping. It is the wrapping of the calculation 
`int ^^ int`. That wrapped calculation result is then used as 
initializer for the enum. Again, the fact that 10^^17 is wrapping 
has nothing to do with enum.


More information about the Digitalmars-d mailing list