Double precision build warnings - A Problem?

rkeene
Posts: 3
Joined: Wed Oct 19, 2011 9:56 pm

Double precision build warnings - A Problem?

Post by rkeene »

I have successfully build bullet 2.79 in both debug and release modes for visual studio 10 C++ in double precision mode. It links and runs ok.

But, when it builds there are tons of warnings (many are duplicates) where double precision btScalar is being assigned to float variables. This is a implied loss of precision.

Several questions:

Most importantly...
1.) Our world is essentially infinite and all world coordinates are double precision in meters. These conversion to float, will they truncate our values?

Secondary...
2.) Does the bullet library get built and tested with a double precision setting very often?

3.) If I was to go through and check every single conversion and try to think wether it is ok or not, and fix it, what does it take to get qualified to check code into the subversion repository?

What appears to have happened is that bullet was written with btScalar to allow for float vs. double but later add-ons did not take that into account and assumed float.

Here are some random cut-n-pastes from the warnings...

Code: Select all

	1>c:\bullet-2.79\src\bulletcollision\collisionshapes\bttriangleinfomap.h(125): warning C4244: '=' : conversion from 'const btScalar' to 'float', possible loss of data

1>c:\bullet-2.79\src\bulletdynamics\constraintsolver\btgeneric6dofspringconstraint.h(88): warning C4244: '=' : conversion from 'const btScalar' to 'float', possible loss of data

1>c:\bullet-2.79\src\linearmath\btserializer.h(406): warning C4127: conditional expression is constant

In general code should never have any warnings. The above three represent what is really just a few places in the code, but inclusion of header files multiple times make it look like lots of lines.

Also when I build the libraries I get way more warnings. The above is only via the header files into my application.

R. Keene - CTO Sandswept Studios

http://www.thedeadlinger.com
dumbo2007
Posts: 66
Joined: Sun Jan 30, 2011 8:46 pm

Re: Double precision build warnings - A Problem?

Post by dumbo2007 »

Yes it seems float has been used directly in some part of the code instead of btScalar

btScalar abstracts the floating point type and allows switching between double & float easily. Its typedefed as double or float based on compile time options in :

<BulletInstallPath>/LinearMath/btScalar.h

Code: Select all

.....
///The btScalar type abstracts floating point numbers, to easily switch between double and single floating point precision.
#if defined(BT_USE_DOUBLE_PRECISION)
typedef double btScalar;
//this number could be bigger in double precision
#define BT_LARGE_FLOAT 1e30
#else
typedef float btScalar;
//keep BT_LARGE_FLOAT*BT_LARGE_FLOAT < FLT_MAX
#define BT_LARGE_FLOAT 1e18f
#endif
....
I am not sure why float was used directly though. Perhaps you can try replacing the float with btScalar
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Double precision build warnings - A Problem?

Post by Erwin Coumans »

Most of the warnings are harmless. Fixing them would make the code ugly in some cases, but it might be worth looking into.

Most warnings are likely assignments to constants, for example
btScalar value = 1.f;

To fix the warning, we could use btScalar value(1.f); or btScalar value = btScalar (1.f);

Bullet should work find in double precision. We need some unit test to avoid regression though.
Thanks,
Erwin
rkeene
Posts: 3
Joined: Wed Oct 19, 2011 9:56 pm

Re: Double precision build warnings - A Problem?

Post by rkeene »

Erwin Coumans wrote:Most of the warnings are harmless. Fixing them would make the code ugly in some cases, but it might be worth looking into.

Most warnings are likely assignments to constants, for example
btScalar value = 1.f;

To fix the warning, we could use btScalar value(1.f); or btScalar value = btScalar (1.f);

Bullet should work find in double precision. We need some unit test to avoid regression though.
Thanks,
Erwin
How does one get permission to commit to the subversion repository?

Is there a doc on the check-in policies and methods?