I
don't really know the answer to your question, so I appologize if this is
wrong, but the cast operator has higher precedence than the multiply. so it's
going to take that 't', cast it to a long, and do the rest in
longs.
I
think you wanted to have another set of parenthesis like
(long)(t*3*nbPoints)
in
any case,
casting
a double to long just like that is not a good idea, you should add an epsilon
to compensate for any numerical innacuracies.
For
example : long
id = (long)(t*3*nbPoints + 0.25);
From:
owner-xsi(at)Softimage.COM [mailto:
owner-xsi(at)Softimage.COM] On Behalf Of
Ahmidou Lyazidi
Posted At: Wednesday, June 06, 2007 3:20
PM
Posted To: xsi
Conversation: [SDK]Double to long in c++
?
Subject: [SDK]Double to long in c++ ?
Hi
In an Operator,we are
trying to convert the datas passed by OperatorContex.GetTime to a long.The
thing that is strange is when I log the value
it seems good, but when I
mutiply it with a fixed value it seems to round it and give me 2 equal
values for 2 differant frame
here is the code and the log:
long
oOffset = oOp.GetParameterValue(L"TimeOffset");
CTime T =
ctxt.GetTime();
Application().LogMessage(L"Current operator Time " +
T.GetAsText());
double t = double(T) + oOffset;
long id = (long) t
* 3 * nbPoints;