-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[C++] Incorrect Float16 Comparison for NaN and signed zero #46739
Copy link
Copy link
Closed
Description
Describe the bug, including details regarding any error messages, version, and platform.
In the code below, two NaN values are considered equal regardless of whetherEqualOptions::nan_equalis set to true or false. The root of the problem lies here, where float16 values with the same memory representation are not correctly handled, and also here, where HalfFloat is implemented as a uint16_t, causing the comparison to return true.
TEST(FloatComparasion, Float16NaN) {
auto half_float_array = ArrayFromJSON(float16(), R"([16.0,NaN])");
auto half_float_array_1 = ArrayFromJSON(float16(), R"([16.0,NaN])");
ASSERT_TRUE(half_float_array->Equals(half_float_array_1, EqualOptions::Defaults().nans_equal(false)));
ASSERT_TRUE(half_float_array->Equals(half_float_array, EqualOptions::Defaults().nans_equal(false)));
}Component(s)
C++
Reactions are currently unavailable