floating point precision

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

floating point precision

Postby PJani » Sun Mar 27, 2011 11:17 am

Hy.
If i have scale 1 unit = 1 meter and float type in newton, how "big"(1000m?) numbers would start to damage newton balance without any scaling involved?
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: floating point precision

Postby Julio Jerez » Sun Mar 27, 2011 11:40 am

I believe 32 float precision wok fine with up to around 8000 units witch requires 14 bits of the 24 bit mantissa, leaving 10 for fraction.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: floating point precision

Postby JernejL » Sun Mar 27, 2011 3:46 pm

If i give you a example, GTA san andreas engine uses -3000..3000 X and -3000 3000 Y floating point range giving it 9000000 square "meters" of surface for the game world. That game's world HUGE, but i think you could go up to -4000..4000 or -5000..5000 to each direction without any noticeable precision issues, just remember to use the negative range aswell.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: floating point precision

Postby PJani » Mon Mar 28, 2011 4:11 am

@Delfi: GTA SA uses smaller scale. if i remember right 1unit in GTASA is not 1m

With 14bit for whole number(including sign bit) [-8196..8196]x[-8196..8196] => 16384x16384m that results in 270 square km!
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: floating point precision

Postby JernejL » Mon Mar 28, 2011 5:23 am

PJani wrote:@Delfi: GTA SA uses smaller scale. if i remember right 1unit in GTASA is not 1m


You are mistaken. 1 unit in gtasa is very close to 1 meter.
The game was made in scotland and they use meteric system, and i modded gta3/vs/sa gta games to death, even made a map viewer for it.. The scale is definetly very close to 1 meter and the used world area is 3000 units from 0,0,0 points in each direction.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: floating point precision

Postby PJani » Mon Mar 28, 2011 5:49 am

Hmm u are right, probably i mixed something up.
I was modding GTA VC like crazy back in days when GTAVC was popular :P, with GTA SA i wasn't playing much.

i am thinking how to solve unstable buoyancy because of floating point precision problem.
Later today i was looking newton source and i was thinking which part actually makes buoyancy very unstable?
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: floating point precision

Postby JernejL » Mon Mar 28, 2011 7:55 am

You probably used some of my editors then, i wrote a dozen of tools for the gta3-sa era of GTAs 8)
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: floating point precision

Postby PJani » Mon Mar 28, 2011 9:13 am

Its very possible i did use some of your tools back then because i tried every single tool i found!
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: floating point precision

Postby Julio Jerez » Mon Mar 28, 2011 10:10 am

what makes buoyancy very unstable in that the code only calculates the force on the fluid, using the volume ratios immersed under the fluid plane,
but it does not consider the viscosity of the fluid to calculate friction of drag. you can read about the drag here.
http://en.wikipedia.org/wiki/Drag_%28physics%29

Instead the code apply a cheesy fixed drag that makes it either very unrealistic or very unstable.
A step up for newer newton version could be to actually calculate the current surface area of the volume under the liquid and calculate a better approximation of the drag.
one way may be to divide the volume into beams beams of equal area and for each beam determine the speed of the front face hit the liquid, them integrate over the the differential torque and force contribution of each beam.
I like this idea because in extend to more than just a flat liquid plane and generalize to any kind of volume.

It can be an interesting feature, but I have not put too much thought on it
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: floating point precision

Postby PJani » Tue Mar 29, 2011 4:02 am

I would never guess the damping is problem!
Hmm thats an excellent idea!
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: floating point precision

Postby JernejL » Tue Mar 29, 2011 5:02 am

Maybe using convex cast against the water plane, & simulating drag based on the projected shape would work.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: floating point precision

Postby Julio Jerez » Tue Mar 29, 2011 10:04 am

PJani wrote:I would never guess the damping is problem!

Oh yes bouyancy forces using the alchymedes principle fall into the cathegory of "Conservatives forces".
Conservatives forces is a force that when they act on a particle, the net work excuted by the motion of the particle is zero. that is there is not lost of energy as the particle moves.
example of Consertive forces are: Spring Mass, Gravity and kenetic / pontencial energy (a rollercoster), Gravitational orbits, the electric and Magnetic field, the Bouyancy, many some others I do not remember now.

Since the action of those forces alone do not lose energy, when they are simulated numerically, the simulation should last for ever (like a spring with not damping force)
however because numercial methods are only aproximation of diferencial equations, they can not reproduce the exact path the particle should follows.
I am not refering to float acuracy, I am talking about the fact that there is not known numerical method that can integrates a secund order differencial equation exactly, not even using exact arithmetic,
and only very few first order differencial equations can be integrated exactly using numerical methods.
they can only reproduce an aproximation of the path, therefore the discrepancy between the ideal path, and the simulated path is translated to a net gain of lost of energy in the simulation.

what makes the simulation stable is if there is a processs that drain an amount of energy that is equal and larger than the energy gained by the integration process.
Friction, Drag and Viscosity are non consevative forces that always lose energy, they can be used to mak a system stable.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron