Рефакторинг 4
This commit is contained in:
@ -1,56 +1 @@
|
||||
#include <myx/math/almost_equal_relative_and_abs.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace math {
|
||||
|
||||
bool almost_equal_relative_and_abs( const float a, const float b,
|
||||
const float maxAbsDiff, const float maxRelDiff )
|
||||
{
|
||||
// Check if the numbers are really close -- needed
|
||||
// when comparing numbers near zero.
|
||||
float diff = fabsf( a - b );
|
||||
if ( diff <= maxAbsDiff )
|
||||
{
|
||||
return( true );
|
||||
}
|
||||
|
||||
float aN = fabsf( a );
|
||||
float bN = fabsf( b );
|
||||
float largest = ( bN > aN ) ? bN : aN;
|
||||
|
||||
if ( diff <= largest * maxRelDiff )
|
||||
{
|
||||
return( true );
|
||||
}
|
||||
return( false );
|
||||
}
|
||||
|
||||
|
||||
bool almost_equal_relative_and_abs( const double a, const double b,
|
||||
const double maxAbsDiff, const double maxRelDiff )
|
||||
{
|
||||
// Check if the numbers are really close -- needed
|
||||
// when comparing numbers near zero.
|
||||
double diff = fabs( a - b );
|
||||
if ( diff <= maxAbsDiff )
|
||||
{
|
||||
return( true );
|
||||
}
|
||||
|
||||
double aN = fabs( a );
|
||||
double bN = fabs( b );
|
||||
double largest = ( bN > aN ) ? bN : aN;
|
||||
|
||||
if ( diff <= largest * maxRelDiff )
|
||||
{
|
||||
return( true );
|
||||
}
|
||||
return( false );
|
||||
}
|
||||
|
||||
} // namespace math
|
||||
|
||||
} // namespace myx
|
||||
#include <myx/math/almost_equal_relative_and_abs-inl.hpp>
|
||||
|
Reference in New Issue
Block a user