PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

64bit 32.32 data type

Hi, ive been experimenting with making a fixed point 64bit 32.32 data type for use in places where I need the numerical precision but cant sacrifice the range (isn’t physics fun!!! Grr)

Ive managed to make a working 64bit multiply without overflow like this

Code:


CFixed32L operator*(const CFixed32L& other) const {


U32 ah = static_cast<U32>(m_v >> 32);
U32 al = static_cast<U32>(m_v);

U32 bh = static_cast<U32>(other.m_v >> 32);
U32 bl = static_cast<U32>(other.m_v);

I64 result = static_cast<U64>(ah*bh)<<32;
result += (static_cast<U64>(ah)*bl)
+ (static_cast<U64>(bh)*al);
result += ( static_cast<U64>(al)*bl)>>32;

result -= ((ah >> 31) * (other.m_v<<32) ) ;
result -= ((bh >> 31) * (m_v<<32) );

return CFixed32L::FromRaw(result);

}





But im a bit stumped how to make a divide, as the top part of the fraction would need to be shifted into a 128bit space, anybody tried this or have any ideas?



[edit] all that code can prob be made MUCH faster but this is a proof of concept at the mo, in the long run i think its all going to be too slow to pursue but im interested if its been done cos ive been playing with it for a while now
http://www.gamedev.net/community/forums ... _id=310251


[If people are wondering why I keep linking this stuff up its because I usually find most of the information I need through forum searches and there’s nothing more annoying than finding a similar question to your query and having no solution]