Jeremy Leach
Senior Member
This is another maths routine for calculating an exact result without overflow. It's approximately 98 bytes long.
You pass the routine the DoubleWord and ByteC values and it calculates the result, leaving the result in ResultWhole and ResultRemainder, where the remainder is a decimal remainder (ie 6 for .6).
The DoubleWord value is made up of a least and most-significant Word, LSW and MSW.
It assumes the result of the calculation is going to fit into a Word.
The explanation for how it works is with the code.
The routine could be useful for averaging, where you accumulate a running sum in a DoubleWord then want to work out the running average over C samples.
It can also be used for calculating WordA * WordB / ByteC (MSW = WordA ** WordB, LSW = WordA * WordB)
You pass the routine the DoubleWord and ByteC values and it calculates the result, leaving the result in ResultWhole and ResultRemainder, where the remainder is a decimal remainder (ie 6 for .6).
The DoubleWord value is made up of a least and most-significant Word, LSW and MSW.
It assumes the result of the calculation is going to fit into a Word.
The explanation for how it works is with the code.
The routine could be useful for averaging, where you accumulate a running sum in a DoubleWord then want to work out the running average over C samples.
It can also be used for calculating WordA * WordB / ByteC (MSW = WordA ** WordB, LSW = WordA * WordB)
Attachments
-
2.7 KB Views: 69
Last edited: