Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"If both of the addends have the same sign, the output must have that sign. However, for x−y that means if x and y have different signs the output must have the sign of x."

This is trivially wrong, or mixing two different meanings of "signs".

Given variables x and y with values 5 and 10, ie both having the same positive sign, x-y will produce a result -5, that has negative sign.

Even if we assume that the sign of the y variable is actually inverted, it's still trivial by choosing say -3 and -6, the latter which has now inverted to 6, and the result is +3, which has different sign than x.



> Given variables x and y with values 5 and 10, ie both having the same positive sign, x-y will produce a result -5, that has negative sign.

If x and y both have a positive sign the condition "for x−y that means if x and y have different signs" is not met.

With -3 and -6, again, x and y both have the same sign and the condition is not met for subtraction.


Direct your attention to the first line "If both of the addends have the same sign, the output must have that sign" This is absolutely not true, as already shown. x=5 y=10 z=x-y=-5, which has different sign from x.

If we assume sign of y inverts because of the operation, then direct your attention to the second line "However, for x−y that means if x and y have different signs the output must have the sign of x" x=-3 y=-6=>6 these now have different sign, so result should have sign of x, but z=x+y=3, which again has different sign from x.


> Direct your attention to the first line "If both of the addends have the same sign, the output must have that sign" This is absolutely not true, as already shown. x=5 y=10 z=x-y=-5, which has different sign from x.

The first sentence is referring to addition, with addends, not subtraction. x - y is not an addition, it is a subtraction, so the first sentence does not directly apply. It does apply however if you treat x - y as the sum x + (-y), which the second sentence clarifies.

In other words, the first sentence applies directly to additions, and applies to subtractions if you flip the sign of the second argument. The second sentence applies to subtractions directly without any sign flips, but obviously does not apply to additions.

> If we assume sign of y inverts because of the operation, then direct your attention to the second line "However, for x−y that means if x and y have different signs the output must have the sign of x"

> x=-3 y=-6=>6 these now have different sign, so result should have sign of x, but z=x+y=3, which again has different sign from x.

No, x=-3 and y=-6 both have the same sign, they're both negative.


You’ve missed the word “different”. Your examples talk about the same sign.


Direct your attention to the first line "If both of the addends have the same sign, the output must have that sign"

This is absolutely not true, as already shown. x=5 y=10 z=x-y=-5, which has different sign from x.

If we assume sign of y inverts because of the operation, then direct your attention to the second line "However, for x−y that means if x and y have different signs the output must have the sign of x" x=-3 y=-6=>6 these now have different sign, so result should have sign of x, but z=x+y=3, which again has different sign from x.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: