[General] Add compareFloats to Utils

This commit is contained in:
David Cernat 2018-07-22 15:23:23 +03:00
parent cb6c37a26d
commit 715cac807d
2 changed files with 7 additions and 1 deletions

View file

@ -91,6 +91,11 @@ bool Utils::compareDoubles(double a, double b, double epsilon)
return fabs(a - b) < epsilon; return fabs(a - b) < epsilon;
} }
bool Utils::compareFloats(float a, float b, float epsilon)
{
return fabs(a - b) < epsilon;
}
// Based on https://stackoverflow.com/a/1489873 // Based on https://stackoverflow.com/a/1489873
unsigned int Utils::getNumberOfDigits(int integer) unsigned int Utils::getNumberOfDigits(int integer)
{ {

View file

@ -28,7 +28,8 @@ namespace Utils
int progressFunc(double TotalToDownload, double NowDownloaded); int progressFunc(double TotalToDownload, double NowDownloaded);
unsigned int getNumberOfDigits(int integer); unsigned int getNumberOfDigits(int integer);
bool compareDoubles(double a, double b, double epsilon); bool compareDoubles(double a, double b, double epsilon = 0.005);
bool compareFloats(float a, float b, float epsilon = 0.005f);
template <class Type, class Type2> template <class Type, class Type2>
bool vectorContains(const std::vector<Type> &vectorChecked, const Type2 &value) bool vectorContains(const std::vector<Type> &vectorChecked, const Type2 &value)