>Michel Rouzic wrote:
> > David Resnick wrote:
> > and the result is a double. Hence, you could do any of these:
> >
> > 1.0/2
> > (double)1/2
> > 1/2.0
> > 1/(double)2
> > 1.0/2.0 /* Probably the clearest, but all work */
> >
> > Don't do this though:
> > (double)(1/2)
> > The cast would be applied too late...
> >
> > If any of the above is wrong, no doubt I'll be corrected 
> >
> > -David
>
> oh ok, i never know whether i get a float or int result, i mean, in my
> case i had to do 1.0/(int variable).
>
The result you get is based on the type. If you have constants,
things of the form "1" are integer constants, and things of the
form "1.0" are double constants. If you do an operation on two
integers, the result is an integer. If you do an operation on
a double and an integer, the result is a double. For other
types (and unsigned vs signed stuff), consult the standard
or a text to see how promotions work.
> how would i do if i wanted to divide two integers as if they were
> floats without using some variable to transtype? just being curious
I showed you 5 ways. What is your queston here? If you
mean a way to interprete 1/2 as division of two floats,
well, you can't. They are integers, and how the division
works is governed by the C standard. You need to cast or do
1.0/2 etc.
Do you mean how to divide a/b with a and b interpreted as doubles?
int a=1;
int b=2;
You just need to cast one of them, as in
double c = (double)a/b;
-David