Strange behaviour

Hi

I have a small problem. It is as follows

#define Inertia 2
#define b 8
#define Dia 2.8
float TauL, TauA, WL, WR, TL, TR;

TL = (b*TauL+TauA)*Dia/(b*4);
TR = (b*TauL-TauA)*Dia/(b*4);
WL = (TL*dT/(Inertia*1000));
WR = (TR*dT/(Inertia*1000));

The above code gives me correct values for WL and WR (viz ~3.96) . where as the following code although calculating the same WL and WR does not give me correct results.(~ -165)

#define Inertia 2
#define b 8
#define Dia 2.8
float TauL, TauA, WL, WR;

WL = ((b*TauL+TauA)*Dia*dT/(b*Inertia*4000));
WR = ((b*TauL-TauA)*Dia*dT/(b*Inertia*4000));

Can someone explain me why this is happening.

I have put only parts of the program where I have a problem.

Thanks Shyam

Code you say works: TL = (b*TauL+TauA)*Dia/(b*4); WL = (TL*dT/(Inertia*1000));

or, subbing TL into the WL equation:

WL = ((b*TauL+TauA)*Dia/(b*4)*dT/(Inertia*1000));

vs code that doesn't work: WL = ((b*TauL+TauA)*Dia*dT/(b*Inertia*4000));

I'm not sure it is re-arranged correctly. You only moved part of (b*4)*dT in with (Inertia*1000) seems like dT should have moved also.

Try putting .0 on your integer constants (inertia, b and 4000). With their current values, the compiler is likely evaluating them as int(signed) and the 64000 result doesn't fit.