equals() method in irrMath.h

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
dude3d
Posts: 25
Joined: Thu Sep 06, 2007 3:45 am

equals() method in irrMath.h

Post by dude3d »

For the following function

Code: Select all

	//! returns if a float equals the other one, taking floating 
	//! point rounding errors into account
	inline bool equals(const f32 a, const f32 b, const f32 tolerance = ROUNDING_ERROR_32)
	{
		return (a + tolerance > b) && (a - tolerance < b);
	}
when a = 600.0, b = 600.0, ROUNDING_ERROR_32 = 0.000001, it returns false. This is driving me crazy.

Does anybody know why this is happening?

Thanks
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Sure, it uses < and > instead of <= and >=. But that was fixed already some time ago, so either make those changes to your sources, or use the 1.4 release/beta.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Sorry if this has already been answered, but why do we define our own ROUNDING_ERROR_32 instead of using FLT_EPSILON?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Because f32 is not equal to float. It might be replaced by some other implementation of low precision non-integer arithmetics. If someone wants to create a proper class of it... It might be useful. Well, maybe when fixed-point arithmetics come in.
Post Reply