Skip to content

Commit

Permalink
Reverted the removal of EPSILON_VALUE, because it broke older code th…
Browse files Browse the repository at this point in the history
…at relied on it.
  • Loading branch information
paulhoux committed Dec 27, 2023
1 parent 4e8916a commit 546ad63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions include/cinder/CinderMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,41 +123,43 @@ struct CI_API math<float>
#define M_PI 3.14159265358979323846
#endif

CI_API inline bool approxZero( float n, float epsilon = FLT_EPSILON )
constexpr double EPSILON_VALUE = 4.37114e-05;

CI_API inline bool approxZero( float n, float epsilon = float(EPSILON_VALUE) )
{
return std::abs( n ) < epsilon;
}

CI_API inline bool approxZero( double n, double epsilon = DBL_EPSILON )
CI_API inline bool approxZero( double n, double epsilon = EPSILON_VALUE )
{
return std::abs( n ) < epsilon;
}

CI_API inline float roundToZero( float n, float epsilon = FLT_EPSILON )
CI_API inline float roundToZero( float n, float epsilon = float(EPSILON_VALUE) )
{
if( std::abs( n ) < epsilon )
return 0.0f;
return n;
}

CI_API inline double roundToZero( double n, double epsilon = DBL_EPSILON )
CI_API inline double roundToZero( double n, double epsilon = EPSILON_VALUE )
{
if( std::abs( n ) < epsilon )
return 0.0;
return n;
}

CI_API inline bool approxEqual( float a, float b, float epsilon = FLT_EPSILON )
CI_API inline bool approxEqual( float a, float b, float epsilon = float(EPSILON_VALUE) )
{
return std::abs( b - a ) < epsilon;
}

CI_API inline bool approxEqual( double a, double b, double epsilon = DBL_EPSILON )
CI_API inline bool approxEqual( double a, double b, double epsilon = EPSILON_VALUE )
{
return std::abs( b - a ) < epsilon;
}

CI_API inline bool approxEqualRelative( float a, float b, float maxRelDiff = FLT_EPSILON )
CI_API inline bool approxEqualRelative( float a, float b, float maxRelDiff = float(EPSILON_VALUE) )
{
// See: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

Expand All @@ -175,7 +177,7 @@ CI_API inline bool approxEqualRelative( float a, float b, float maxRelDiff = FLT
return false;
}

CI_API inline bool approxEqualRelative( double a, double b, double maxRelDiff = DBL_EPSILON )
CI_API inline bool approxEqualRelative( double a, double b, double maxRelDiff = EPSILON_VALUE )
{
// See: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

Expand Down
2 changes: 1 addition & 1 deletion src/cinder/audio/dsp/Dsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ float spectralCentroid( const float *magArray, size_t magArrayLength, size_t sam
A += mag;
}

if( A < EPSILON )
if( A < EPSILON_VALUE )
return 0;

return FA / A;
Expand Down

0 comments on commit 546ad63

Please sign in to comment.