1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-31 00:07:39 +02:00

Fix float comparisons

Replace this "==" with a more tolerant comparison operation.
Floating point numbers should not be tested for equality cpp:S1244
This commit is contained in:
Alexander Wilms
2024-02-14 23:30:29 +01:00
parent 110ef5f66e
commit 2ea78a5883
4 changed files with 5 additions and 5 deletions

View File

@@ -232,7 +232,7 @@ namespace
std::string multipleOfCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
{
double result = data.Float() / schema.Float();
if (floor(result) != result)
if (!vstd::isAlmostEqual(floor(result), result))
return validator.makeErrorMessage((boost::format("Value is not divisible by %d") % schema.Float()).str());
return "";
}