In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Zoot wrote: Peter -- this libs are fairly similar to my own math libs, although I handle banking for tmp variables a little differently. In any case, one thing I noticed is that you are not accounting for rounding, something I do in my own functions, e.g. (simplified example, my actual libs have more ASM).... [code] FUNC MATH_DIV IF __PARAMCNT < 4 THEN __PARAM4 = 0 IF __PARAMCNT < 3 THEN __PARAM3 = __PARAM2 __PARAM2 = 0 ENDIF ENDIF tmpW1 = __WPARAM12 tmpW2 = __WPARAM34 \CLC ' add 1/2 of divisor for cleaner rounding \RR __PARAM4 \RR __PARAM3 tmpW1 = tmpW1 + __WPARAM34 tmpW1 = tmpW1 / tmpW2 RETURN tmpW1 ENDFUNC [code] For my mid-multiply (*/) function I do something similar, but obviously #128 is added to the first word since the divisor is always 256. In any case, I've found that this gives me much closer integer results, esp. when numbers may be manipulated a bit (a good example would be encoder odometry and trig). ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=329435#m329768 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)