Pop Quizzzzzzzz
Pop Quizzzzzzzz
05 Jan 2014, 12:17
A short Pop quizzzzz:
1. What is the output of?
double r = 5 / 100; Print(r.ToString());
Replies
jeex
07 Jan 2014, 16:55
t
aTrader: that's exactly my point.
It's absolutely absurd that r = 0, while r is a double. If i want r to be have the value that suits a double, i have to typecast both numerator and denominator.
double r = (double)x / (double) y;
I do not know of one language that does not use / as a simple devider with a double as result, but makes it as ambiguous as c#.
@jeex
hichem
08 Jan 2014, 11:46
RE: t
If you knew how compilers work you wouldn't find it absurd. because x / y is evaluated before r. The compiler doesn't care if the result will be affected to a double when calculating x/y, for the compiler x/y is a division of two integers, thus the result should be an integer.
jeex said:
aTrader: that's exactly my point.
It's absolutely absurd that r = 0, while r is a double. If i want r to be have the value that suits a double, i have to typecast both numerator and denominator.
double r = (double)x / (double) y;I do not know of one language that does not use / as a simple devider with a double as result, but makes it as ambiguous as c#.
@hichem
atrader
07 Jan 2014, 11:17
try:
@atrader