Page 1 of 1

[HD Pg 0, Sec. 5.1.5 - numeric-promotion-and-casting]

Posted: Sun Nov 25, 2018 7:38 am
by flex567
Does numeric promotion applies to wrappers as well?

Re: [HD Pg 0, Sec. 5.1.5 - numeric-promotion-and-casting]

Posted: Sun Nov 25, 2018 10:13 am
by admin
Good question. Yes, it does. So, the following will not compile -
Byte b1 = 10;
Byte b2 = -b1;
The book should have mentioned this. Will get it updated.
thank you for your feedback,
Paul.

Re: [HD Pg 0, Sec. 5.1.5 - numeric-promotion-and-casting]

Posted: Sun Nov 25, 2018 4:07 pm
by flex567
When will be the book updated? I am using Kindle version, will I receive the update?

Re: [HD Pg 0, Sec. 5.1.5 - numeric-promotion-and-casting]

Posted: Sun Nov 25, 2018 10:07 pm
by admin
We update the version after a few errors are reported. There is no fixed schedule.
Regarding Kindle, I think Amazon delivers the updated version automatically to existing customers but I am not sure about when they do it.

HTH,
Paul.

Re: [HD Pg 0, Sec. 5.1.5 - numeric-promotion-and-casting]

Posted: Wed May 08, 2019 11:00 am
by flex567
2. Binary numeric promotion - Both the operands of a binary operator are promoted to an int but if any of the operands is larger than an int, the other operand is promoted to the same type as the type of the larger one. Thus, for example, if both the operands are of type byte,
then both are promoted to int but if any of the operands is a long, float, or double, the other one is also promoted to long, float, or double, respectively.
It is not mentioned what happens in case one operand is double and the other is long ??

Re: [HD Pg 0, Sec. 5.1.5 - numeric-promotion-and-casting]

Posted: Wed May 08, 2019 11:28 am
by admin
It says, "if any of the operands is larger than an int, the other operand is promoted to the same type as the type of the larger one" and then, "For example, if any of the operands is a long, float, or double, the other one is also promoted to long, float, or double, respectively".
So, between long and double, double is larger, so long will be promoted to double.
Should be improved for clarity.