On Friday, 18 January 2019 at 17:15:09 UTC, Steven Schveighoffer wrote:
What is 127 + 127? Answer: 254. Which if converted to a byte is -127. Not what you might expect if you are doing addition.

Quite similar to int.max + int.max

In fact, D promotes all integral types smaller than int to int to do arithmetic. And if the result might not fit into what you are assigning it to, it requires a cast or mask.

Then why isn't int + int = long? If i did the example above, they wouldn't fit in a int for sure, yet the result is of the same type. Why should byte be any different?

Reply via email to