Skip to content

Commit

Permalink
Tidying up.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhoux committed Dec 29, 2023
1 parent f2eb0c6 commit b98f807
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions include/cinder/CinderMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,12 @@ CI_API inline bool approxZero( double n, double epsilon = EPSILON_VALUE )

CI_API inline float roundToZero( float n, float epsilon = float(EPSILON_VALUE) )
{
if( approxZero( n, epsilon ) )
return 0.0f;
return n;
return approxZero( n, epsilon ) ? 0.0f : n;
}

CI_API inline double roundToZero( double n, double epsilon = EPSILON_VALUE )
{
if( approxZero( n, epsilon ) )
return 0.0;
return n;
return approxZero( n, epsilon ) ? 0.0 : n;
}

CI_API inline bool approxEqual( float a, float b, float epsilon = float(EPSILON_VALUE) )
Expand All @@ -165,12 +161,12 @@ CI_API inline bool approxEqualRelative( float a, float b, float maxRelDiff = flo
// See: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

// Calculate the difference.
float diff = std::abs( a - b );
a = std::abs( a );
b = std::abs( b );
const float diff = std::abs( a - b );

// Find the largest.
float largest = ( b > a ) ? b : a;
a = std::abs( a );
b = std::abs( b );
const float largest = ( b > a ) ? b : a;

if( diff <= largest * maxRelDiff )
return true;
Expand All @@ -183,12 +179,12 @@ CI_API inline bool approxEqualRelative( double a, double b, double maxRelDiff =
// See: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

// Calculate the difference.
double diff = std::abs( a - b );
a = std::abs( a );
b = std::abs( b );
const double diff = std::abs( a - b );

// Find the largest.
double largest = ( b > a ) ? b : a;
a = std::abs( a );
b = std::abs( b );
const double largest = ( b > a ) ? b : a;

if( diff <= largest * maxRelDiff )
return true;
Expand Down

0 comments on commit b98f807

Please sign in to comment.