|
-
May 25th, 2004, 03:43 PM
#1
Thread Starter
Addicted Member
Optimizing single-precision floating-point variables
I am currently working on making a physics engine. It involves a lot of matrix math, so I am thinking about using D3DX (part of DirectX) for speed reasons. The problem with this is that DirectX uses singles for its vectors.
My question is how do I get the most out of the singles, I want all the accuracy I can get. The single is 32-bit, but it uses an exponent. I think its layout looks like this:
Code:
S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF
0 1 8 9 31
S = Sign bit
E = Exponent bits
F = Fraction bits
Now using the sign bit and the fraction bits to their full extent gives me 24 bits that should allow for a range of 2^24 or 16,777,216. This doesn't seem like enough accuracy.
Now clearly the 8-bit exponent gives me a lot more room, but I don't know how to fully use it. If I were to use the full range of the exponent it would leave huge "gaps" in my numbers.
Anyway, how do I get the most out of this data type? Any advice would be helpful.
Thanks!
-
May 25th, 2004, 11:54 PM
#2
So Unbanned
The big thing about accuracy isn't so much the variable type. The single is plenty accurate enough. The problems are the equations, calculationg on numerous objects, numerous forces, etc... after a while things slow down -it's inevitable. So the real issue is deciding how accurate your equations will be, and that's basically by deciding how much you take into perspective(gravity, wind, and various other kinetic, and potential energies, etc.).
-
May 26th, 2004, 01:08 AM
#3
Thread Starter
Addicted Member
Thanks for your reply, but I'm not sure I properly described my problem.
The largest range of adjacent numbers I can see a 32-bit single holding is 16,777,216. The largest range a 32-bit integer can hold, however, is 4,294,967,296.
All I am looking for is tips, tricks, articles, or anything to get better accuracy from a single.
-
May 27th, 2004, 05:11 PM
#4
Lively Member
If you wanted more accuracy you could use some of the E's as an extension of the F's, redistributing the precision between the exponent and the fraction. Exponents rarely need to be as large as 256, especially if you're modelling real-world physics, so I'd try maybe swapping 4 of the E's for F's. That way you get a maximum exponent of 16 and the precision of the fraction goes up four-fold.
I think...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|