Integer math library for sxb 2.0
Attached is a library for integer math.
This library contains wrapper functions that implement
the *, /, //, */ and ** operators for 16bits signed and unsigned variables,
plus 32bits addition and subtraction. As these operators generate quite
a bit of code, calling a subroutine might save some codespace.
I didn't bother including wrapper functions for 8bit variables as the calling
overhead would prabably cancel out any space saving.
regards peter
This library contains wrapper functions that implement
the *, /, //, */ and ** operators for 16bits signed and unsigned variables,
plus 32bits addition and subtraction. As these operators generate quite
a bit of code, calling a subroutine might save some codespace.
I didn't bother including wrapper functions for 8bit variables as the calling
overhead would prabably cancel out any space saving.
regards peter
Comments
inside a seperate $ifused block. Sorry about that.
regards peter
For my mid-multiply (*/) function I do something similar, but obviously #128 is added to the first word since the divisor is always 256.
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).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
I added wrapper functions for roundoff versions (thanks Zoot for mentioning that)
and some functions that deal with 16bit fractions, eg. converting between 65536 based fractions
and 10000 based·fractions which are·great for displaying decimals of a fractional number.
Also included a function (signed and unsigned) to calculate the 65536 based fraction for a given
numerator and denominator.
regards peter
·
Thanks for that ..
Regards,
John Twomey
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Those who can, do.Those who can’t, teach.