Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

An outrageous question. OUTRAGE!
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Mon Dec 21, 2009 12:40 am    Post subject: Reply with quote

Bagne wrote:
I'm trying to understand that first example you gave me. That was for software floating point, yes? Are a1 and b1 significands, and a2,b2 exponents?
What's the 2^15 do?


The first example applies to both fixed and floating point. No, a1/a2 were two halves of the significand: you can not directly multiply two 32 bit numbers; it'll overflow enormously. You can only multiply at most two arbitrary 15 bit integers and be certain that the result will fit in a signed 32 bit word (the result will be at most 30 bits, plus 1 bit for sign). Therefore, you have to do your multiplication in pieces, as I showed: probably use just 31 instead of 32 bits (recovering that extra bit looks like a lot of trouble), split each 30 bit (not including sign bit) integer into two 15 bit pieces, multiply two pieces at a time, and sum them back together.

Quote:
I need to multiply in fixed point. How do I do that? Do I just use your first example and set the exponents to ... I donno, 1? (improving precision by storing only values smaller than ... 10?)
Adding in software fixed point should be normal, right?


Multiplying is nearly the same. Assuming a 3 bit integer and 27 bit fractional part (and one bit wasted, but beware that 3 bits integer could overflow while summing together the imaginary component), you'll represent a number as (splitting into 15 bit pieces)
a * 2 ^ -27 = a1 * 2 ^ -12 + a2 * 2 ^ -27
So
Code:

  (a1 * 2^-12 + a2 * 2^-27) * (b1 * 2^-12 + b2 * 2^-27)
= a1*b1 * 2^-24 + (a1*b2 + a2*b1) * 2^-39 + a2*b2 * 2^-54
= (a1*b1 * 2^3 + (a1*b2 + a2*b1) * 2^-12 + a2*b2 * 2^-27) * 2^-27

Interestingly, the a2*b2 piece is no longer insignificant: it now adds 3 bits instead of appearing off the end.

However, the catch is multiplying negative numbers! When splitting a negative number into two, you need to make sure both of those pieces are negative, which is NOT what using an and mask will give you.

And yes, adding is done normally. Thank goodness.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
AJHunter
Probably Naked




Joined: 04 Dec 2009
Posts: 131
Location: Usually bed

PostPosted: Mon Dec 21, 2009 4:09 am    Post subject: Reply with quote

Exclamation Exclamation Exclamation Ahh... so this is what you wanted to do... You are now the third-coolest person ever! (the first two are, repectively, Chuck Norris and Mr. T) What?!?!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group