also if any one knows of the procedure or a white sheets on setting up physX to work with doubles that too would be totally awesome as well
Double to Float
#1 Members - Reputation: 439
Posted 10 October 2012 - 03:31 PM
also if any one knows of the procedure or a white sheets on setting up physX to work with doubles that too would be totally awesome as well
#2 Moderators - Reputation: 7796
Posted 10 October 2012 - 03:50 PM
Most libraries out there use floats. Mixing floats and doubles is a well-documented performance issue on DirectX and other libraries. Switching from double-precision to single-precision is an expensive thing.
Is there really something that you really need the extra few bits of precision for?
#3 Members - Reputation: 439
Posted 10 October 2012 - 04:54 PM
#4 Members - Reputation: 328
Posted 10 October 2012 - 10:28 PM
float PI = 3.14; float ConvertFloat = (double)PI; -- or -- double AnotherPie = PI;
However, floats are used in most 3D Applications instead of doubles. But if you insist - go ahead and try and see what your results are. If you feel the performance is getting a punch then this would be the reason behind using floats instead of doubles. I forgot how many bytes doubles use but they're way different than floats.
#5 Moderators - Reputation: 5028
Posted 10 October 2012 - 10:44 PM
#6 Moderators - Reputation: 13585
Posted 10 October 2012 - 11:38 PM
Yeah, when creating a D3D9 device, it sets some flags in the CPU to tell it to round all it's results to 32-bit precision. You've got to set the D3DCREATE_FPU_PRESERVE flag when creating your D3D9 device to avoid this.I believe it was DirectX changing the FPU mode to float, whereas Lua wanted doubles. Things could be different now, though.
#7 Members - Reputation: 1626
Posted 11 October 2012 - 12:27 AM
With all of that said I understand that many coders think bigger is better and that using a double in place of a float will give you the ability to have larger maps, worlds, more precision in game and all that jazz. However that is simply untrue, video cards themselves fall flat on their face when you get anywhere near those sizes. So I guess in short, I would suggest coders just be in the habit of using floats unless there is some extenuating circumstance wherein you actually do need the extra range.
Digivance Game Studios Founder:
Dan Mayor - Dan@Digivance.com
www.Digivance.com
#8 Members - Reputation: 439
Posted 11 October 2012 - 12:35 AM
#9 Members - Reputation: 1952
Posted 11 October 2012 - 12:56 AM
Range is not everything; You have completely side-stepped the issue of precision. So either you aren't aware of how floating point works, or you're conveinently only telling half of the story to make it seem more convincing.Just wanted to chime in, probably a bit late but anyway. Floating point variables have a range of something like 1234510. Although this is difficult to place actual range of numbers to it is important to remember that floating point variables are normally used for positions, velocities and other 3D calculations. It is very rare that you will ever encounter a level map, model, mesh or really any 3D asset that even comes close to peaking out the maximum allowable values of a float.
With all of that said I understand that many coders think bigger is better and that using a double in place of a float will give you the ability to have larger maps, worlds, more precision in game and all that jazz. However that is simply untrue, video cards themselves fall flat on their face when you get anywhere near those sizes. So I guess in short, I would suggest coders just be in the habit of using floats unless there is some extenuating circumstance wherein you actually do need the extra range.
Floats are essentially scientific notation.
The larger your float value is, the less precise it is. With IEEE754 floats, all decimal precision is completely gone at by the time you reach 8388608.
From there is only gets worse. if you add 16777216.f and 1.f for example, you get 16777216 again! For proof, test the following assert:
assert(16777216.f + 1.f != 16777216.f);Mathematically you would certainly excpect the result of adding one 1 to have an effect, but it doesn't because 16777217.f can't be represented.
For many things, you need much more precision than that well before you get that high. Floats just don't provide that.
Don't get me wrong though, floats are still very very useful in a lot of cases. I even have a C++ class that provides fully IEEE754 compliant 16-bit "half" floats, at close to the speed of regular floats, for when saving memory is of the utmost importance.
But... it's just not as cut and dry as you make it out to be.
Edited by iMalc, 11 October 2012 - 01:01 AM.
My website dedicated to sorting algorithms
#10 Moderators - Reputation: 5028
Posted 11 October 2012 - 07:37 AM
Just wanted to chime in, probably a bit late but anyway. Floating point variables have a range of something like 1234510. Although this is difficult to place actual range of numbers to it is important to remember that floating point variables are normally used for positions, velocities and other 3D calculations. It is very rare that you will ever encounter a level map, model, mesh or really any 3D asset that even comes close to peaking out the maximum allowable values of a float.
With all of that said I understand that many coders think bigger is better and that using a double in place of a float will give you the ability to have larger maps, worlds, more precision in game and all that jazz. However that is simply untrue, video cards themselves fall flat on their face when you get anywhere near those sizes. So I guess in short, I would suggest coders just be in the habit of using floats unless there is some extenuating circumstance wherein you actually do need the extra range.
I believe that the developers on the original Dungeon Siege encountered precision problems while building their continuous world, hence their switch to a hybrid system using chained local coordinate spaces. It really isn't as hard as you might think to start encountering precision problems using single-precision floats. Awhile back, I built a quick and dirty little streaming system for my isometric game, and it really only took me about 20 min to hit the "end of the world", where precision problems started cropping up. You can have large floats and you can have precise floats, but large precise floats are a different story.
#11 Members - Reputation: 328
Posted 11 October 2012 - 08:27 AM
@OP, simply casting your doubles to floats in the standard manner shown by SIC Games should be all you need. There's no trick to it. This will generate CPU assembly to read your 64-bit double from RAM into an FPU register (expanding the value to register precision, e.g. 80-bit), then write the contents of that register to a 32-bit float RAM address (rounding the value to 32-bit precision)
Yeah, when creating a D3D9 device, it sets some flags in the CPU to tell it to round all it's results to 32-bit precision. You've got to set the D3DCREATE_FPU_PRESERVE flag when creating your D3D9 device to avoid this.I believe it was DirectX changing the FPU mode to float, whereas Lua wanted doubles. Things could be different now, though.
Thanks bro for agreeing. I also like to add that when I tried to convert my mesh file from float to double - it didn't draw correctly until I switched it back to float. Though a XMVECTOR willt ake a double just it's less nessary. Hope this forum has helped out. It doesn't hurt to try and see for yourself though.






