Shop OBEX P1 Docs P2 Docs Learn Events
Floating point division always giving similar fractional? — Parallax Forums

Floating point division always giving similar fractional?

scurrierscurrier Posts: 32
edited 2010-11-17 17:19 in Propeller 1
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.
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

Sign In or Register to comment.