[SOLVED] Spinner Increment/Decrement

If you found a bug in our library or on our website, please report it in this section. In this forum you can also make concrete suggestions or feature requests.

Moderators: CEGUI MVP, CEGUI Team

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

[SOLVED] Spinner Increment/Decrement

Postby Van » Tue Nov 03, 2009 07:18

CEGUI 0.7.1 SVN Branch

Code: Select all

   mSpinnerUnits = (CEGUI::Spinner *) CEGUI::WindowManager::getSingleton().createWindow( CEGUILOOK"/Spinner", mStr );
   mSpinnerUnits->setMinimumValue( 1.0f );
   mSpinnerUnits->setStepSize( 0.01f );
   mSpinnerUnits->setTextInputMode( CEGUI::Spinner::TextInputMode::FloatingPoint );
   mSpinnerUnits->setMaximumValue( 31.0f );
   mSpinnerUnits->setCurrentValue( 31.0f );


Spinner Down Arrow: 31.00 -> 30.99
Spinner Down Arrow: 30.99 -> 30.98
Spinner Down Arrow: 30.98 -> 30.9700000001
Spinner Down Arrow: 30.9700000001 -> 30.9600000001
Spinner Down Arrow: 30.9600000001 -> 30.9500000002

Why?
Last edited by Van on Thu Nov 05, 2009 00:52, edited 1 time in total.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Re: [BUG] Spinner Increment/Decrement

Postby scriptkid » Tue Nov 03, 2009 11:27

This is a hardware (cpu) limitation. Oddly, i could not come up with a link (quickly) so maybe i was searching with the wrong words.
[edit] found something: http://www.cygnus-software.com/papers/c ... floats.htm[/edit]

It all has to do with the same reason why you should never compare floating point numbers exactly, but within a margin.
Check out my released snake game using Cegui!

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Re: [BUG] Spinner Increment/Decrement

Postby Van » Tue Nov 03, 2009 13:10

Didn't have this problem in CEGUI 0.6.x. So what changed and why?

The floating point "error" is a from poor compiler implementation (Microsoft being one of the worst) and poor processor implementation (intel has gotten real lazy).

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Re: [BUG] Spinner Increment/Decrement

Postby scriptkid » Tue Nov 03, 2009 19:07

Didn't have this problem in CEGUI 0.6.x. So what changed and why?


Not sure, but a long time ago (rev. 1741) the spinner had its math changed from float to double.

Maybe you are using a different compiler or otherwise different setup now?
Check out my released snake game using Cegui!

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Re: [BUG] Spinner Increment/Decrement

Postby Van » Thu Nov 05, 2009 00:52

Compiler: MSVS 9.0+

Bad Compiler! Bad!


Code: Select all

float getObjectTypeMinimumUnit(void)
{
  double mUnit = 1.0f;

// PROBLEM HERE
  if ( something ) mUnit  = 0.01f;
// PROBLEM HERE

  return mUnit;
}

... somewhere in code life ...
   double mUnit =  MyObject->getObjectTypeMinimumUnit();

// PROBLEM HERE
   mUnit = 0.0993156789;
// PROBLEM HERE

   mSpinnerUnits->setMinimumValue( mUnit );

... somewhere in code life ...


The fix is to remove the numerical suffix f and add a trailing zero.

Code: Select all

double getObjectTypeMinimumUnit(void)
{
  double mUnit = 1.0;
  if ( something ) mUnit = 0.010;
  return mUnit;
}


Return to “Bug Reports, Suggestions, Feature Requests”

Who is online

Users browsing this forum: No registered users and 3 guests