Rounding Numbers with the Propeller
coryco2
Posts: 107
Is there any simple way to round a run-time variable floating point number to the nearest integer on the Propeller? I'm looking for something that will work like ROUND does for constants.
Comments
-Phil
http://forums.parallax.com/showthread.php?127302-F32-Concise-floating-point-code-for-the-Propeller
and I like it. For that one you would use code like "rounded = f32.FRound( inputVal )"
-Phil
When you divide it truncates. Use the modulus operator (//) to get the fractional part.
http://forums.parallax.com/showthread.php?130486-Spin-Pop-Quiz-what-s-wrong-with-the-SetPosition-method.
Another thing to be careful about is that the Propeller will happily use integer operations on floating point numbers. Since Spin is loosely typed it won't complain, but the results will be wrong. If you look in that code in my thread you'll see I carefully convert back and forth when I need to. As Mike points out, you can pre-compute floating point constants using the Spin complier. I did that for various radian angle constants as they are all fractions of Pi.