On 9 Jan 2005 19:57:06 GMT, Joona I Palaste <>
wrote in comp.lang.c:
> tings <> scribbled the following:
> > int a, b, c, d;
> > ...
> > a = b*((double)c/d);
>
> > Can someone clarify what's happening step by step in the statement?
>
> > Thanks for your help!
>
> Let's take it step by step, shall we?
> It assigns something to a.
> This something is a product of two multiplicands. The first is b.
> The second is the quotient of two dividends.
Just terminology, but there are not two dividends in a division.
There is one dividend and one divisor. This is different from the
situation for multiplication, because order does not matter for
multiplication but it does for division.
a * b == b * a
....but:
a/b != b/a
> The first dividend is (double)c, which is c cast to a double.
> The second dividend is d.
So actually, the dividend is (double)c, and the divisor is d.
> In other words, the second multiplicand is c divided by d, only that c
> is cast to a double to prevent the "cutting-off" that occurs when an
> int is dived by an int.
>
> In yet other words, it assigns to a a new value, this value being b
> multiplied by the quotient of c and d. The (double) bit is only there
> to ensure a proper mathematical division instead of the "cutting-off"
> integer division C would otherwise perform.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html