Skip to content

[C++] Incorrect Float16 Comparison for NaN and signed zero #46739

@andishgar

Description

@andishgar

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++

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions