• Welcome to Final Fantasy Hacktics. Please login or sign up.
 
April 27, 2024, 09:14:35 pm

News:

Don't be hasty to start your own mod; all our FFT modding projects are greatly understaffed! Find out how you can help in the Recruitment section or our Discord!


Floating Point Multiplication

Started by formerdeathcorps, June 28, 2011, 12:36:06 am

formerdeathcorps

June 28, 2011, 12:36:06 am Last Edit: June 28, 2011, 12:42:45 am by formerdeathcorps
OK, here's a way to implement floating point multiplication in FFT.  Here's a basic outline from me (SA, feel free to improve this routine's register use efficiency):

r1 = numerator
r2 = denominator
r3 = FFFFFFFF
r4 = INT PART
r5 = FRAC PART
IF r1 < r2, r3 = r3 / r2 * r1 + 1
ELSE:
  r3 = r3 / r2 + 1
  r2 = 1
DO r4 * r3
r4 = MFHI
r6 = MFLO
DO r5 * r3
r3 = MFHI
r5 = r3 + r6
If r5 < r3, then r4 = r4 + 1 (carry-over)
If r2 = 1, then:
  DO r4 * r1
 r4 = MFLO
  DO r5 * r1
 r6 = MFHI
 r5 = MFLO
 r4 = r4 + r6.

Anyone care to code this?
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Glain

I'm starting to wonder if we can get away with something like...

r2 = (numerator)
r3 = (denominator)

and if you want to multiply fractions, just multiply (numerator) * (numerator) and (denominator) * (denominator) and then at the very end, just do (r2 / r3).

Seems like it'd be way simpler but I'm not sure how high r2 and r3 might get. Then again you've got 32 bits and you're probably only working with a final damage number that's a halfword anyway. I don't know... it's a thought. Seems like less work if we can get away with it.
  • Modding version: Other/Unknown