AK: Fix is_within_range when converting from float

Within range now uses the max capacity of a type rather than its size.
This fixes some subtests in
https://wpt.fyi/results/wasm/core/conversions.wast.js.html?product=ladybird
This commit is contained in:
me-it-is 2025-09-13 16:41:10 -07:00 committed by Sam Atkins
parent 193163be2f
commit b76f1fb011
Notes: github-actions[bot] 2025-09-24 09:41:40 +00:00
2 changed files with 19 additions and 2 deletions

View file

@ -445,3 +445,20 @@ TEST_CASE(should_constexpr_make_via_factory)
{
[[maybe_unused]] constexpr auto value = make_checked(42);
}
TEST_CASE(is_within_range_float_to_int)
{
static_assert(AK::is_within_range<int>(0.0));
static_assert(AK::is_within_range<int>(0.0f));
static_assert(AK::is_within_range<int>(((long double)0.0)));
static_assert(!AK::is_within_range<int>(NumericLimits<float>::max()));
static_assert(!AK::is_within_range<int>(NumericLimits<double>::max()));
static_assert(!AK::is_within_range<int>(NumericLimits<long double>::max()));
static_assert(!AK::is_within_range<int>(NumericLimits<float>::lowest()));
static_assert(AK::is_within_range<long>(0.0));
static_assert(AK::is_within_range<long long>(0.0));
static_assert(!AK::is_within_range<int>(NAN));
}