| 2423 | |
| 2424 | template <typename TYPE> |
| 2425 | void CheckFloatApproxEqualsWithUlpDistance() { |
| 2426 | using CType = |
| 2427 | std::conditional_t<is_half_float_type<TYPE>::value, Float16, typename TYPE::c_type>; |
| 2428 | auto type = TypeTraits<TYPE>::type_singleton(); |
| 2429 | std::vector<CType> a, b; |
| 2430 | a = {CType(NAN), CType(+0.0), CType(INFINITY)}; |
| 2431 | b = {CType(NAN), CType(-0.0), CType(INFINITY)}; |
| 2432 | if constexpr (is_half_float_type<TYPE>::value) { |
| 2433 | a.push_back(Float16(1.00097656)); |
| 2434 | b.push_back(Float16(0.999511719f)); |
| 2435 | } else if constexpr (std::is_same_v<TYPE, DoubleType>) { |
| 2436 | a.push_back(CType(0.9999999999999999)); |
| 2437 | b.push_back(CType(1.0000000000000002)); |
| 2438 | } else if constexpr (std::is_same_v<TYPE, FloatType>) { |
| 2439 | a.push_back(CType(1.0000001f)); |
| 2440 | b.push_back(CType(0.99999994f)); |
| 2441 | } |
| 2442 | |
| 2443 | std::shared_ptr<Array> array_a, array_b; |
| 2444 | ArrayFromVector<TYPE>(type, a, &array_a); |
| 2445 | ArrayFromVector<TYPE>(type, b, &array_b); |
| 2446 | auto options = EqualOptions::Defaults().ulp_distance(2); |
| 2447 | |
| 2448 | // Check with NaN |
| 2449 | ASSERT_FALSE(array_a->Equals(array_b, options)); |
| 2450 | ASSERT_TRUE(array_a->Equals(array_b, options.nans_equal(true))); |
| 2451 | |
| 2452 | // Check With Signed Zero |
| 2453 | ASSERT_FALSE( |
| 2454 | array_a->Equals(array_b, options.nans_equal(true).signed_zeros_equal(false))); |
| 2455 | |
| 2456 | // Check with Ulp Distance |
| 2457 | ASSERT_FALSE(array_a->Equals(array_b, options.nans_equal(true).ulp_distance(1))); |
| 2458 | } |
| 2459 | |
| 2460 | TEST(TestPrimitiveAdHoc, FloatingApproxEquals) { |
| 2461 | CheckApproxEquals<FloatType>(); |
nothing calls this directly
no test coverage detected