Skip to content

Commit

Permalink
Math: Adds Compare() method
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Aug 19, 2021
1 parent 550c858 commit 2a24181
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Math.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#ifndef MATH_ENUM_H
#define MATH_ENUM_H

/* Enumeration for Math conditions. */
/* Enumeration for Math comparison operators. */
enum ENUM_MATH_CONDITION {
MATH_COND_EQ = 1, // Argument values are equal.
MATH_COND_GT = 2, // First value is greater than second.
Expand Down
18 changes: 18 additions & 0 deletions Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ class Math {
return _hundreds ? _result * 100 : _result;
}

/**
* Checks condition for 2 values based on the given comparison operator.
*/
template <typename V1, typename V2>
static bool Compare(V1 _v1, V2 _v2, ENUM_MATH_CONDITION _op = MATH_COND_EQ) {
switch (_op) {
case MATH_COND_EQ:
return _v1 == _v2;
case MATH_COND_GT:
return _v1 > _v2;
case MATH_COND_LE:
return _v1 < _v2;
default:
break;
}
return false;
}

/**
* Gets number of digits after decimal in a floating point number.
*/
Expand Down

0 comments on commit 2a24181

Please sign in to comment.