Suppress float-equal warning

This commit is contained in:
Björn Schäpers
2022-08-01 14:00:14 +02:00
parent 64fcf4c2b6
commit d1130c9d39
3 changed files with 9 additions and 0 deletions

View File

@@ -23,6 +23,7 @@
#pragma once
#include <gsl/gsl-lite.hpp>
#include <units/bits/external/hacks.h>
#include <units/bits/math_concepts.h>
#include <units/bits/pow.h>
#include <units/bits/ratio_maths.h>
@@ -36,9 +37,12 @@ struct decimal_fp {
[[nodiscard]] constexpr decimal_fp to_decimal(double v) noexcept
{
UNITS_DIAGNOSTIC_PUSH
UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
if (v == 0) {
return {.significant = 0.0, .exponent = 0};
}
UNITS_DIAGNOSTIC_POP
double significant = abs(v);
std::intmax_t exponent = 0;

View File

@@ -45,6 +45,7 @@
UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \
UNITS_PRAGMA(GCC diagnostic ignored X)
#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF
#define UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL UNITS_DIAGNOSTIC_IGNORE("-Wfloat-equal")
#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES UNITS_DIAGNOSTIC_IGNORE("-Wmissing-braces")
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND UNITS_DIAGNOSTIC_IGNORE("-Wnon-template-friend")
@@ -56,6 +57,7 @@
#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : 4068))
#define UNITS_DIAGNOSTIC_IGNORE(X) UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : X))
#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF UNITS_DIAGNOSTIC_IGNORE(4296)
#define UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA UNITS_DIAGNOSTIC_IGNORE(4244)
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND

View File

@@ -155,9 +155,12 @@ constexpr T int_power(T base, std::integral auto exp)
constexpr auto checked_multiply = [](auto a, auto b) {
const auto result = a * b;
UNITS_DIAGNOSTIC_PUSH
UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
if (result / a != b) {
throw std::overflow_error{"Wraparound detected"};
}
UNITS_DIAGNOSTIC_POP
return result;
};