Original Post
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) i dont have a fpu to play with so no why dont you use doubles etc please.. Ive managed to make a working 64bit multiply without overflow like this
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 [edit 2] High performance is the name of the game btw :) so fast suggestions please ;-)