From f3336fbe2d862c55fd8af43e642b71023ca5d0bb Mon Sep 17 00:00:00 2001 From: HUDSoftware Date: Wed, 19 Jun 2024 15:19:01 +0200 Subject: [PATCH] Fix sanitizer --- interface/core/i128/i128_intrinsics.h | 4 +- test/u128.cpp | 283 -------------------------- test/u128/u128_assign.cpp | 2 +- test/u128/u128_constructors.cpp | 31 +-- 4 files changed, 6 insertions(+), 314 deletions(-) delete mode 100644 test/u128.cpp diff --git a/interface/core/i128/i128_intrinsics.h b/interface/core/i128/i128_intrinsics.h index 4b2670c..3b62d17 100644 --- a/interface/core/i128/i128_intrinsics.h +++ b/interface/core/i128/i128_intrinsics.h @@ -347,17 +347,16 @@ namespace hud /** Construct a i128 from f32. */ constexpr u128_intrinsics(f32 value) noexcept - : value_ {static_cast(value)} { // Check value is not NaN or infinite hud::check(hud::math::is_finite(value)); // Ensure we are positive hud::check(value > -1); + value_ = static_cast(value); } /** Construct a i128 from f64. */ constexpr u128_intrinsics(f64 value) noexcept - : value_ {static_cast(value)} { // Check value is not NaN or infinite hud::check(hud::math::is_finite(value)); @@ -365,6 +364,7 @@ namespace hud hud::check(value > -1); // Check value is lower than 2^128 hud::check(value < hud::math::ldexp(static_cast(1), 128)); + value_ = static_cast(value); } /////////////////////////// diff --git a/test/u128.cpp b/test/u128.cpp deleted file mode 100644 index a9f90cc..0000000 --- a/test/u128.cpp +++ /dev/null @@ -1,283 +0,0 @@ -#include // std::nextafter, std::ldexp - -GTEST_TEST(u128, default_constructor) -{ - u128 v; - hud_assert_ne(v, 0); -} - -GTEST_TEST(u128, constructor_init) -{ - u128 v {}; - hud_assert_eq(v, 0); -} - -GTEST_TEST(u128, constructor_i8) -{ - // Init to 0 - { - hud::u128 v {i8 {}}; - hud_assert_eq(v, (i8 {})); - } - - // Init to min value - { - hud::u128 v {hud::i8_min}; - hud_assert_eq(v, hud::i8_min); - } - - // Init to max value - { - hud::u128 v {hud::i8_max}; - hud_assert_eq(v, hud::i8_max); - } -} - -GTEST_TEST(u128, constructor_i16) -{ - // Init to 0 - { - hud::u128 v {i16 {}}; - hud_assert_eq(v, i16 {}); - } - - // Init to min value - { - hud::u128 v {hud::i16_min}; - hud_assert_eq(v, hud::i16_min); - } - - // Init to max value - { - hud::u128 v {hud::i16_max}; - hud_assert_eq(v, hud::i16_max); - } -} - -GTEST_TEST(u128, constructor_i32) -{ - // Init to 0 - { - hud::u128 v {i32 {}}; - hud_assert_eq(v, i32 {}); - } - - // Init to min value - { - hud::u128 v {hud::i32_min}; - hud_assert_eq(v, hud::i32_min); - } - - // Init to max value - { - hud::u128 v {hud::i32_max}; - hud_assert_eq(v, hud::i32_max); - } -} - -GTEST_TEST(u128, constructor_i64) -{ - // Init to 0 - { - hud::u128 v {i64 {}}; - hud_assert_eq(v, i64 {}); - } - - // Init to min value - { - hud::u128 v {hud::i64_min}; - hud_assert_eq(v, hud::i64_min); - } - - // Init to max value - { - hud::u128 v {hud::i64_max}; - hud_assert_eq(v, hud::i64_max); - } -} - -GTEST_TEST(u128, constructor_f32) -{ - // Init to 0 - { - hud::u128 v {f32 {}}; - hud_assert_eq((float)v, f32 {}); - } - - // Init to min positive value - { - f32 value = hud::f32_min_positive; - // Check value is not NaN or infinite - hud_assert_true(std::isfinite(value)); - // Ensure we are positive - hud_assert_true(value > -1); - - hud::u128 v {hud::f32_min}; - - // Cast to u32 because f32_min is the lowest positive value of an f32 - hud_assert_eq(static_cast(v), static_cast(value)); - } - - // Init to max value - { - // Compute the greatest value - f32 value = hud::f32_max; - - hud::u128 v {value}; - // Check value is not NaN or infinite - hud_assert_true(std::isfinite(value)); - // Ensure we are positive - hud_assert_true(value > -1); - - hud_assert_eq(static_cast(v), value); - } -} - -GTEST_TEST(u128, constructor_f64) -{ - // Init to 0 - { - hud::u128 v {f64 {}}; - hud_assert_eq((float)v, f64 {}); - } - - // Init to min positive value - { - f64 value = hud::f64_min_positive; - // Check value is not NaN or infinite - hud_assert_true(std::isfinite(value)); - // Ensure we are positive - hud_assert_true(value > -1); - // Check value is lower than 2^128 - hud_assert_true(value < std::ldexp(static_cast(1), 128)); - - hud::u128 v {value}; - hud_assert_eq(static_cast(v), static_cast(hud::f64_min)); - } - - // Init to big value - { - // Compute the greatest value just before 2^128 - f64 value = std::nextafter(std::ldexp(1.0, 128), 0.0); - - // Check value is not NaN or infinite - hud_assert_true(std::isfinite(value)); - // Ensure we are positive - hud_assert_true(value > -1); - // Check value is lower than 2^128 - hud_assert_true(value < std::ldexp(static_cast(1), 128)); - - hud::u128 v {value}; - hud_assert_eq(static_cast(v), value); - } -} - -GTEST_TEST(u128, constructor_u128) -{ - // Init to 0 - { - hud::u128 v {hud::u128 {0}}; - hud_assert_eq(v, hud::u128 {0}); - } - - // Init to min value - { - hud::u128 v {hud::u128_min}; - hud_assert_eq(v, hud::u128_min); - } - - // Init to max value - { - hud::u128 v {hud::u128_max}; - hud_assert_eq(v, hud::u128_max); - } -} - -GTEST_TEST(u128, constructor_i128) -{ - // Init to 0 - { - hud::u128 v {hud::i128 {0}}; - hud_assert_eq(v, static_cast(hud::i128 {0})); - } - - // Init to min value - { - hud::u128 v {hud::i128_min}; - hud_assert_eq(v, static_cast(hud::i128_min)); - } - - // Init to max value - { - hud::u128 v {hud::i128_max}; - hud_assert_eq(v, static_cast(hud::i128_max)); - } -} - -GTEST_TEST(u128, constructor_high_low) -{ - - { - hud::u128 v {0, 0}; - hud_assert_eq(v.high(), 0); - hud_assert_eq(v.low(), 0); - } - - { - hud::u128 v {hud::u64_max, 0}; - hud_assert_eq(v.high(), hud::u64_max); - hud_assert_eq(v.low(), 0); - } - - { - hud::u128 v {0, hud::u64_max}; - hud_assert_eq(v.high(), 0); - hud_assert_eq(v.low(), hud::u64_max); - } -} - -#if defined(HD_INTRINSIC_INT128_SUPPORTED) -GTEST_TEST(u128, constructor__int128) -{ - // Init to 0 - { - hud::u128 v {__int128 {0}}; - hud_assert_eq(v, static_cast(hud::i128 {0})); - } - - // Init to min value - { - hud::u128 v {hud::i128_min}; - hud_assert_eq(v, static_cast(hud::i128_min)); - } - - // Init to max value - { - hud::u128 v {hud::i128_max}; - hud_assert_eq(v, static_cast(hud::i128_max)); - } -} - -GTEST_TEST(u128, constructor_unsigned__int128) -{ - // Init to 0 - { - unsigned __int128 value {0}; - hud::u128 v {value}; - hud_assert_eq(v, static_cast(hud::i128 {0})); - } - - // Init to min value - { - hud::u128 v {hud::i128_min}; - hud_assert_eq(v, static_cast(hud::i128_min)); - } - - // Init to max value - { - hud::u128 v {hud::i128_max}; - hud_assert_eq(v, static_cast(hud::i128_max)); - } -} - -#endif \ No newline at end of file diff --git a/test/u128/u128_assign.cpp b/test/u128/u128_assign.cpp index 3623ba6..f95d27f 100644 --- a/test/u128/u128_assign.cpp +++ b/test/u128/u128_assign.cpp @@ -141,7 +141,7 @@ GTEST_TEST(u128, assign_f64) hud::u128 v {hud::u128_max}; v = value; - hud_assert_eq(static_cast(v), static_cast(hud::f64_min)); + hud_assert_eq(static_cast(v), static_cast(hud::f64_min_positive)); } // Init to big value diff --git a/test/u128/u128_constructors.cpp b/test/u128/u128_constructors.cpp index 1e9f975..9f9423d 100644 --- a/test/u128/u128_constructors.cpp +++ b/test/u128/u128_constructors.cpp @@ -106,13 +106,8 @@ GTEST_TEST(u128, constructor_f32) // Init to min positive value { - f64 value = hud::f32_min_positive; - // Check value is not NaN or infinite - hud_assert_true(std::isfinite(value)); - // Ensure we are positive - hud_assert_true(value > -1); - - hud::u128 v {hud::f32_min}; + f32 value = hud::f32_min_positive; + hud::u128 v {value}; // Cast to u32 because f32_min is the lowest positive value of an f32 hud_assert_eq(static_cast(v), static_cast(value)); @@ -122,12 +117,7 @@ GTEST_TEST(u128, constructor_f32) { // Compute the greatest value just before 2^128 f32 value = std::nextafterf(std::numeric_limits::max(), 0.0); - hud::u128 v {value}; - // Check value is not NaN or infinite - hud_assert_true(std::isfinite(value)); - // Ensure we are positive - hud_assert_true(value > -1); hud_assert_eq(static_cast(v), value); } @@ -144,29 +134,14 @@ GTEST_TEST(u128, constructor_f64) // Init to min positive value { f64 value = hud::f64_min_positive; - // Check value is not NaN or infinite - hud_assert_true(std::isfinite(value)); - // Ensure we are positive - hud_assert_true(value > -1); - // Check value is lower than 2^128 - hud_assert_true(value < std::ldexp(static_cast(1), 128)); - hud::u128 v {value}; - hud_assert_eq(static_cast(v), static_cast(hud::f64_min)); + hud_assert_eq(static_cast(v), static_cast(hud::f64_min_positive)); } // Init to big value { // Compute the greatest value just before 2^128 f64 value = std::nextafter(std::ldexp(1.0, 128), 0.0); - - // Check value is not NaN or infinite - hud_assert_true(std::isfinite(value)); - // Ensure we are positive - hud_assert_true(value > -1); - // Check value is lower than 2^128 - hud_assert_true(value < std::ldexp(static_cast(1), 128)); - hud::u128 v {value}; hud_assert_eq(static_cast(v), value); }