forked from mpusz/mp-units
Suppress float-equal warning
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gsl/gsl-lite.hpp>
|
#include <gsl/gsl-lite.hpp>
|
||||||
|
#include <units/bits/external/hacks.h>
|
||||||
#include <units/bits/math_concepts.h>
|
#include <units/bits/math_concepts.h>
|
||||||
#include <units/bits/pow.h>
|
#include <units/bits/pow.h>
|
||||||
#include <units/bits/ratio_maths.h>
|
#include <units/bits/ratio_maths.h>
|
||||||
@@ -36,9 +37,12 @@ struct decimal_fp {
|
|||||||
|
|
||||||
[[nodiscard]] constexpr decimal_fp to_decimal(double v) noexcept
|
[[nodiscard]] constexpr decimal_fp to_decimal(double v) noexcept
|
||||||
{
|
{
|
||||||
|
UNITS_DIAGNOSTIC_PUSH
|
||||||
|
UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
|
||||||
if (v == 0) {
|
if (v == 0) {
|
||||||
return {.significant = 0.0, .exponent = 0};
|
return {.significant = 0.0, .exponent = 0};
|
||||||
}
|
}
|
||||||
|
UNITS_DIAGNOSTIC_POP
|
||||||
|
|
||||||
double significant = abs(v);
|
double significant = abs(v);
|
||||||
std::intmax_t exponent = 0;
|
std::intmax_t exponent = 0;
|
||||||
|
2
src/core/include/units/bits/external/hacks.h
vendored
2
src/core/include/units/bits/external/hacks.h
vendored
@@ -45,6 +45,7 @@
|
|||||||
UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \
|
UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \
|
||||||
UNITS_PRAGMA(GCC diagnostic ignored X)
|
UNITS_PRAGMA(GCC diagnostic ignored X)
|
||||||
#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF
|
#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_LOSS_OF_DATA
|
||||||
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES UNITS_DIAGNOSTIC_IGNORE("-Wmissing-braces")
|
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES UNITS_DIAGNOSTIC_IGNORE("-Wmissing-braces")
|
||||||
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND UNITS_DIAGNOSTIC_IGNORE("-Wnon-template-friend")
|
#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_PRAGMAS UNITS_PRAGMA(warning(disable : 4068))
|
||||||
#define UNITS_DIAGNOSTIC_IGNORE(X) UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : X))
|
#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_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_LOSS_OF_DATA UNITS_DIAGNOSTIC_IGNORE(4244)
|
||||||
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||||
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND
|
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND
|
||||||
|
@@ -155,9 +155,12 @@ constexpr T int_power(T base, std::integral auto exp)
|
|||||||
|
|
||||||
constexpr auto checked_multiply = [](auto a, auto b) {
|
constexpr auto checked_multiply = [](auto a, auto b) {
|
||||||
const auto result = a * b;
|
const auto result = a * b;
|
||||||
|
UNITS_DIAGNOSTIC_PUSH
|
||||||
|
UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
|
||||||
if (result / a != b) {
|
if (result / a != b) {
|
||||||
throw std::overflow_error{"Wraparound detected"};
|
throw std::overflow_error{"Wraparound detected"};
|
||||||
}
|
}
|
||||||
|
UNITS_DIAGNOSTIC_POP
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user