1. ## factoring - baffled

Any ideas why these 2 expressions (as far as I can see = exactly the same), give vastly different results:

Code:
`Y = Y + (T/6)*(2*V + 2*P + 2*P + T*S);`
I make the following change (introduce T in to the brackets...
Code:
`Y = Y + (1/6)*(T*2*V + T*2*P + T*2*P + T*T*S);`
Using the second line of code instead of the first gives a vastly different answer?

any ideas as to why? I am completely clueless

2. What are the types involved? Integer division might come into play. What are the ranges of the values involved? Maybe the result of the intermediate computations exceed the maximum value for the given type.

3. Well 1/6 is probably zero since you're probably using integer division. T/6 may or may not be the same thing, it depends on the type of T.

4. All doubles.

Oh I see. So what is the best way to perform (1/6):

Code:
`static_cast<double>(1/6)`
?

5. Originally Posted by strokebow
So what is the best way to perform (1/6)
Just write (1.0 / 6.0)

Originally Posted by strokebow
Code:
`static_cast<double>(1/6)`
?
That's another way of writing 0.0

6. Thanks both for the help!