Floating point division always giving similar fractional?
scurrier
Posts: 32
Hello all,
I am using fdiv to compute how far a fan has moved since the last fan blade was sensed. Here is some code:
lastedge and period are addresses marking longs that are updated with integer values by another cog. Lastedge is the number of clocks since the last blade was detected. Period represents the number of clocks between blades from the last cycle.
That debug line keeps outputting something like 1059194816. I can put my hand in front of the sensor and it hovers around that value. I am expecting that it should show a full range of values.
Does this sound familiar to anyone?
Maybe there's a better question... is there a better way to count how long it has been (in terms of percent to the next blade) since the last blade passed using integers? I feel like there should be some way, but I can't think of it.
Thank you
I am using fdiv to compute how far a fan has moved since the last fan blade was sensed. Here is some code:
lastedge and period are addresses marking longs that are updated with integer values by another cog. Lastedge is the number of clocks since the last blade was detected. Period represents the number of clocks between blades from the last cycle.
depth := f.fdiv( f.ffloat( cnt - long[lastedge] ),f.ffloat( long[period] ) ) debug.dec( f.frac( depth ) )
That debug line keeps outputting something like 1059194816. I can put my hand in front of the sensor and it hovers around that value. I am expecting that it should show a full range of values.
Does this sound familiar to anyone?
Maybe there's a better question... is there a better way to count how long it has been (in terms of percent to the next blade) since the last blade passed using integers? I feel like there should be some way, but I can't think of it.
Thank you
Comments
John Abshier
Using fixed point math to calculate percent:
http://stackoverflow.com/questions/4201747/looking-for-good-substitute-for-calculating-percentage-employing-integer-math