Z
zl2k
hi,
In a function of a class, I have a unsigned long A (65535) and a
double B (0-1) and when I calculate a*b I should get a double 0-65535.
But, I get an unreasonable large value (e+9) if doing "cout<<A*B;".
However, I get the correct value if doing "cout<<B*A;" or
"cout<<(double)A*B". Can someone explain what's wrong with the code?
If I take the piece out of the function and run it separately, both
A*B and B*A give the same correct result. Thanks for the comments.
zl2k
In a function of a class, I have a unsigned long A (65535) and a
double B (0-1) and when I calculate a*b I should get a double 0-65535.
But, I get an unreasonable large value (e+9) if doing "cout<<A*B;".
However, I get the correct value if doing "cout<<B*A;" or
"cout<<(double)A*B". Can someone explain what's wrong with the code?
If I take the piece out of the function and run it separately, both
A*B and B*A give the same correct result. Thanks for the comments.
zl2k