Skip to content

Commit

Permalink
Fix sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
HUD-Software committed Jun 19, 2024
1 parent 334146c commit f3336fb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 314 deletions.
4 changes: 2 additions & 2 deletions interface/core/i128/i128_intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,24 +347,24 @@ namespace hud

/** Construct a i128 from f32. */
constexpr u128_intrinsics(f32 value) noexcept
: value_ {static_cast<unsigned __int128>(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<unsigned __int128>(value);
}

/** Construct a i128 from f64. */
constexpr u128_intrinsics(f64 value) noexcept
: value_ {static_cast<unsigned __int128>(value)}
{
// Check value is not NaN or infinite
hud::check(hud::math::is_finite(value));
// Ensure we are positive
hud::check(value > -1);
// Check value is lower than 2^128
hud::check(value < hud::math::ldexp(static_cast<f64>(1), 128));
value_ = static_cast<unsigned __int128>(value);
}

///////////////////////////
Expand Down
283 changes: 0 additions & 283 deletions test/u128.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion test/u128/u128_assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ GTEST_TEST(u128, assign_f64)

hud::u128 v {hud::u128_max};
v = value;
hud_assert_eq(static_cast<u64>(v), static_cast<u64>(hud::f64_min));
hud_assert_eq(static_cast<u64>(v), static_cast<u64>(hud::f64_min_positive));
}

// Init to big value
Expand Down
31 changes: 3 additions & 28 deletions test/u128/u128_constructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>(v), static_cast<u32>(value));
Expand All @@ -122,12 +117,7 @@ GTEST_TEST(u128, constructor_f32)
{
// Compute the greatest value just before 2^128
f32 value = std::nextafterf(std::numeric_limits<f32>::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<f32>(v), value);
}
Expand All @@ -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<f64>(1), 128));

hud::u128 v {value};
hud_assert_eq(static_cast<u64>(v), static_cast<u64>(hud::f64_min));
hud_assert_eq(static_cast<u64>(v), static_cast<u64>(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<f64>(1), 128));

hud::u128 v {value};
hud_assert_eq(static_cast<f64>(v), value);
}
Expand Down

0 comments on commit f3336fb

Please sign in to comment.