<Solved> Strange result when multiplying two double numbers

Problems building or running the engine, queries about how to use features etc.
Post Reply
Doc_QuicknDirty
Gnoblar
Posts: 16
Joined: Mon Aug 30, 2010 4:48 pm
x 1

<Solved> Strange result when multiplying two double numbers

Post by Doc_QuicknDirty »

Hello,

Can anyone please explain me the logic behind this in Orge 1.7:

Code: Select all

double tmp = 47.6 * 6378137.0; // tmp  = 303599321.19999999
O.k. that's what I expected, but:

Code: Select all

double con = 6378137.0;
double tmp = 47.6 * con; // tmp = 303599328.00000000
The multiplication doesn't work no matter if OGRE_DOUBLE_PRECISION is set to 1 or 0.

I would be grateful for any hint.

Best wishes

Ralf
Last edited by Doc_QuicknDirty on Thu Sep 30, 2010 1:22 pm, edited 2 times in total.
User avatar
Fish
Greenskin
Posts: 131
Joined: Fri Aug 22, 2008 6:12 pm

Re: Why is Ogre too stupid to multiply two double numbers?

Post by Fish »

What does this have to do with Ogre? Is this not a computer science issue: an issue of double/float precision?
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: Why is Ogre too stupid to multiply two double numbers?

Post by madmarx »

I could answer you with the following lines :
"
Why does this result be the same even when you don't use OGRE ?
Why did you not discriminate between a static optimisation and a code that is evaluated at run time ?
Why didn't you read the generated assembly to check that?
And most of all, why did you assume that doubles have more than 8 valid digits on your platform ?
"

So please change the offensive title :wink: .

Anyway, hope this helps.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 7
Contact:

Re: Why is Ogre too stupid to multiply two double numbers?

Post by haffax »

team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Strange result when multiplying two double numbers

Post by Kojack »

Are you using the direct3d renderer? If so, what option do you have set for the floating point mode in the config dialog? (This is unrelated to the OGRE_DOUBLE_PRECISION setting)
The default behaviour of Direct3D is to turn the FPU to single precision mode, even for doubles. Ogre can prevent that, but only if you put the mode to "consistent" instead of "fastest".
Doc_QuicknDirty
Gnoblar
Posts: 16
Joined: Mon Aug 30, 2010 4:48 pm
x 1

Re: Strange result when multiplying two double numbers

Post by Doc_QuicknDirty »

Hello,

I forgot: platform Windows 7 with VS2005

@madmax
Title changed.

The result is NOT the same when I don't use Ogre.

Code: Select all

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
{

   double tmp1 = 47.6 * 6378137.0; // tmp1  = 303599321.19999999

   double con = 6378137.0;
   double tmp2 = 47.6 * con; // tmp2  = 303599321.19999999

   // Create application object
   OgreDemoApplication app;
  
  //From now on the calculation for tmp2 doesn't work any more

...
Best wishes

Ralf
Doc_QuicknDirty
Gnoblar
Posts: 16
Joined: Mon Aug 30, 2010 4:48 pm
x 1

Re: Strange result when multiplying two double numbers

Post by Doc_QuicknDirty »

Hello,

@Kojack
Billion thanks! You saved my day!!!

Best wishes

Ralf
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58
Contact:

Re: <Solved> Strange result when multiplying two double numb

Post by betajaen »

You can also try adjusting the floating point model in your project settings.

ALT-F7, C/C++, Code Generation, Floating Point Model.

If I remember correctly Ogre has it on "fast", and your other app is likely on precise.
Post Reply