On Sunday, 22 February 2015 at 02:15:29 UTC, Almighty Bob wrote:
what bothers me is any automatic conversion from float to int.
It should never be automatic.
Should 5.5 + 5 compile? I suppose it arguably shouldn't but
that'd probably be pretty annoying and no information is lost -
it can convert 5 (the int) to 5.0 (the float) and add it without
dropping a part of the number.
But int = float would truncate the decimal and that's not cool.
You could argue this same logic ought to apply to a+=b and you'd
have a point, but I think it is different because += happens in a
single step: calculate in-place, rather than calculate the right
hand side then assign to the left hand side. There's no
intermediate to lose precision from, it is all done in that
single step.
"Assign Expressions:
The right operand is implicitly converted to the type of the
left operand"
which quite clearly is not the case since...
a=b; // causes an error. but..
It tries to implicitly convert but can't.