byte + byte = int: why?
Mek101
oidgemek101 at gmail.com
Fri Jan 18 17:26:35 UTC 2019
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?
More information about the Digitalmars-d-learn
mailing list