Mohan S N <[EMAIL PROTECTED]> wrote:
>  --- Thomas Hruska <[EMAIL PROTECTED]> wrote:
>
>  > Ananth wrote:
>  > > On 9/14/07, Jim Dougherty <[EMAIL PROTECTED]> wrote:
>  > >>  [email protected] wrote:
>  > >>  > aot=1/2*b*h;
>  > >>  > Equvilent to
>  > >>  > aot = 1/(2*b*h);
>  > >>  >
>  > >>  > That why your ans is 0.00000
>  > >>  >
>  > >>  > Your can try this
>  > >>  > aot = b*h*1/2;
>  > >>  >
>  > >>
>  > >>  This is bad advice.
>  > >>
>  > >>  1/2*b*h  is NOT equivalent to  1/(2*b*h)
>  > >>
>  > >>  Division and multiplication are of equal precedence.
>  > >>  If you want to add parenthesis to make the order of operations
>  > clearer then:
>  > >>
>  > >>  1/2*b*h  is equiv to  ((1/2)*b)*h
>  > >>
>  > >>  The answer is 0.0 because (1/2) is integer division whose result
>  > is 0.
>  > >>
>  > >>  To correct your problem do one of the following:
>  > >>
>  > >>  aot = 0.5*b*h;
>  > >>
>  > >>  or
>  > >>
>  > >>  aot = b*h/2;
>  > >
>  > > Simple thumb of rule I've always followed:
>  > > (1) Cast all variables in a statement to same type
>
>  why why why?

Why do you want to compare\compute variables of different data types?
(1) is to avoid surprises

Cheers
- Ananth

Reply via email to