Shop OBEX P1 Docs P2 Docs Learn Events
UnsignedIntMath class updated — Parallax Forums

UnsignedIntMath class updated

Peter VerkaikPeter Verkaik Posts: 3,956
edited 2005-12-22 11:18 in General Discussion
I have updated the UnsignedIntMath class with
unsigned integer division and fraction calculation for
signed and unsigned division. I have put an extensive
explanation for the approximations in the class.
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/math/
Test results:

Test program for UnsignedIntMath class
test· 123/678 = 11889/65536 = 1814/10000
····· results·· 11889/65536·· 1814/10000
test -123/678 = 11889/65536 = 1814/10000
····· results·· 11889/65536·· 1814/10000
test 0x0123/0x0678 = 11516/65536 = 1757/10000
·········· results·· 11516/65536·· 1757/10000
test 0x9123/0x0678 = 22 + 28612/65536 = 22 + 4365/10000
·········· results·· 22·· 28610/65536······· 4366/10000
test 0x0123/0xABCD =·· 433/65536 =·· 66/10000
·········· results···· 432/65536···· 66/10000
test 0x9123/0xABCD = 55364/65536 = 8447/10000
·········· results·· 55364/65536·· 8448/10000
Program has finished

If anyone has ways of increasing the accuracy, please comment.

regards peter
·

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-22 11:18
    I updated the UnsignedIntMath class with a usqrt(x) method
    that calculates the root of an·unsigned integer. The result has an
    integer part and fraction part (root equals I + F/256).
    For example usqrt(3) in 8.8 fixed point is·1.187 (integer 1 in highbyte, fraction 187 in lowbyte)

    187/256=0.73 so usqrt(3) = 1.73 decimal

    Also uploaded a Trig class for sin,cos,tan,arcsin,arccos,arctan and atan2
    with 0.1 degree resolution.

    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/math/

    regards peter
Sign In or Register to comment.