R
rk
I am surprised about the results (stated in the comments) from the
following operations:
private void button1_Click(object sender, EventArgs e)
{
uint u34 = 0;
double d34 = u34 - 1; // 4294967295.0
double d34a = u34 + (-1); // -1
double d34b = u34 - (+1); // 4294967295.0
}
Since the second operand is of type int, according to the rules given in
the C# specification for "Binary numeric promotions" (section 14.2.6.2)
Binary numeric promotion occurs for the operands of the predefined +,
–, *, /, %, &, |, ^, ==, !=, >, <, >=, and <= binary operators. Binary
numeric promotion implicitly converts both operands to a common type
...
and
• Otherwise, if either operand is of type uint and the other operand
is of type sbyte, short, or int, both operands are converted to type
long.
I would expect both operands to be converted to long, giving the result
-1 in any of the three cases.
Why is the result -1 for d34 and d34b? What I am missing?
Thanks
Richard
following operations:
private void button1_Click(object sender, EventArgs e)
{
uint u34 = 0;
double d34 = u34 - 1; // 4294967295.0
double d34a = u34 + (-1); // -1
double d34b = u34 - (+1); // 4294967295.0
}
Since the second operand is of type int, according to the rules given in
the C# specification for "Binary numeric promotions" (section 14.2.6.2)
Binary numeric promotion occurs for the operands of the predefined +,
–, *, /, %, &, |, ^, ==, !=, >, <, >=, and <= binary operators. Binary
numeric promotion implicitly converts both operands to a common type
...
and
• Otherwise, if either operand is of type uint and the other operand
is of type sbyte, short, or int, both operands are converted to type
long.
I would expect both operands to be converted to long, giving the result
-1 in any of the three cases.
Why is the result -1 for d34 and d34b? What I am missing?
Thanks
Richard