11-22-2007 10:12 PM
int nd = (int) (double) delay/(double) Ts
delay = 1.98, Ts = 0.01
result : nd = 99;
int nd = delay/Ts
nd = 197
int nd = ceil(delay/Ts)
nd = 198
does anyone know why?
Happy thanksgiving.
machman
11-23-2007 01:25 AM
Where is the connection to LabVIEW?
Can you enlighten us what you perceive as the "interesting" part?
11-23-2007 12:32 PM
11-23-2007 01:22 PM
11-23-2007 02:34 PM
11-23-2007 02:41 PM
oh yeah thats totally what is happening to get that first result! Good call
If it was
int nd = int(delay)/Ts;
instead of
int nd = int(delay/Ts);
then it would do exactly as dan said.
In C, if you have an int divided by a floating point, the integer is immediately promoted to floating point, and the result is floating point, however you have converted a float to an int, truncating all precision, then it is reconverted to a float for the divide operation, however it can't regain precision, so it is ~ 1/0.01, and for the reasons I mentioned before, that ends up as 99.999999, which is converted to an int...floor(99.99999) = 99.
11-23-2007 04:06 PM
Thanks guys, I think I know what's going on.
Machman