Home > Back-end >  Comparison can be directly compared the type double?
Comparison can be directly compared the type double?

Time:05-28

Equal osg3.6.3 platform, including Matrixd class, determine the code is as follows:

 Boolean operator==(const Matrixd& M) const {return compare (m)==0; } 


Int Matrix_implementation: : compare (const Matrix_implementation & amp; M) const
{
Const Matrix_implementation: : value_type * LHS=reinterpret_cast & lt; Const Matrix_implementation: : value_type * & gt; (_mat);
Const Matrix_implementation: : value_type * end_lhs=LHS + 16;
Const Matrix_implementation: : value_type * RHS=reinterpret_cast & lt; Const Matrix_implementation: : value_type * & gt; (m. _mat);
for(; LHS!=end_lhs; + + + + LHS and RHS)
{
If (* LHS & lt; * RHS) return 1;
If (* RHS & lt; * LHS) return 1;
}
return 0;
}
//the typedef float value_type;

I remember the type double, compare equal is like this?
 if (d1 & lt; D2 + how & amp; & D1 & gt; D2 - how) 

How is the tolerance, I set in order to how=0.000001;
So, what is above the osg source code?

CodePudding user response:

* * LHS and RHS is of type Matrix_implementation: : value_type, not what you thought of double

Besides, even if you actually use, will Matrix_implementation: : value_type is defined as double
It can also be overloaded operator & lt; And use what you have said in its concrete implementation how

To learn in the IDE, the right mouse button point you don't understand the symbols, and choose to define,

CodePudding user response:

And perhaps use==whether two Matrixd instances are equal, objective
Is a judgment to another assignment, by calling a copy constructor replication;
Rather than is used to determine a desired results, the other is through a lot of steps to calculate the result, whether the two approximately equal in meet some how scope (due to computer floating-point said after calculating the inevitable error: http://bbs.csdn.net/topics/390676437) floating-point format,
If you need to determine whether the actual approximately equal in meet some how scope, can use the existing or write another such as
 int isApproximateEequal (Matrixd & amp; A, Matrixd & amp; b); 


  • Related