|
Atari coding BBS
Re: carry overflow step decision |
Posted by: ggn
|
Mar,09.2025-14:04
|
Just to clarify, I guess you mean "add.w dn,d0" as you say you accumulate the results in d0?
But anyway. If I understand you correctly, you want to round your fraction and take decision on the rounded number rather than the actual, and this is what what I type below is all about.
The naive way we do rounding is to add 0.5 and take the integer part, so int(x+0.5). If we generalise this, we add the half of our unit, i.e. our "1".
When we have base 16 16.16 fractional numbers our unit is "10000" as we reserve 2 bytes for fraction. Therefore, our 0.5 is $8000. Just add this to your number and then check for overflows etc. That's it. Basically we need to copy d0 to some other register and add $8000.
If that last bit sounds fiddly, then we can simplify this furhter. If we don't really need to keep track of the actual fraction, we can pre-add that $8000 at initialisation. Then the value will automatically be rounded. And to keep everything in order, also add $8000 to the destination value.
What this means in practice: If you want to interpolate (for example) between $150000 and $310000, modify those to $158000 and $3180000. Then you get rounding and your limits are still correct.
(There are several other things to consider when rounding, but this is the main idea)
Hope this helps! Let us know if this makes sense or you have further questions.
|
[All messages in this thread] [Start new thread]
What's the anti-troll code? That's your personal code to be able to add comments and messages on the dhs.nu site.
Don't have a code or forgot it? Fix it here.
|