js8544 commented on code in PR #36667:
URL: https://github.com/apache/arrow/pull/36667#discussion_r1266066589


##########
cpp/src/arrow/util/decimal_test.cc:
##########
@@ -1119,6 +1137,35 @@ class TestDecimalToReal : public ::testing::Test {
     // 2**64 + 2**41 (exactly representable in a float)
     CheckDecimalToReal<Decimal, Real>("18446746272732807168", 0, 
1.8446746e+19f);
     CheckDecimalToReal<Decimal, Real>("-18446746272732807168", 0, 
-1.8446746e+19f);
+
+    // Integers are always exact
+    auto scale = Decimal::kMaxScale - 1;
+    std::string seven = "7.";
+    for (int32_t i = 0; i < scale; ++i) {
+      seven += "0";
+    }
+    CheckDecimalToReal<Decimal, Real>(seven, scale, 7.0f);
+    CheckDecimalToReal<Decimal, Real>("-" + seven, scale, -7.0f);
+
+    CheckDecimalToReal<Decimal, Real>("99999999999999999999.0000000000000000", 
16,
+                                      99999999999999999999.0f);
+    CheckDecimalToReal<Decimal, 
Real>("-99999999999999999999.0000000000000000", 16,
+                                      -99999999999999999999.0f);
+
+    // Small fractions are within one ULP
+    CheckDecimalToRealWithinOneULP<Decimal, Real>("9999999.9", 1, 9999999.9f);
+    CheckDecimalToRealWithinOneULP<Decimal, Real>("-9999999.9", 1, 
-9999999.9f);
+    CheckDecimalToRealWithinOneULP<Decimal, Real>("9999999.999999", 6, 
9999999.999999f);
+    CheckDecimalToRealWithinOneULP<Decimal, Real>("-9999999.999999", 6, 
-9999999.999999f);
+
+    // Large fractions are within 2^-23
+    constexpr Real epsilon = 1.1920928955078125e-07f;  // 2^-23
+    CheckDecimalToRealWithinEpsilon<Decimal, Real>(
+        "112334829348925.99070703983306884765625", 23, epsilon,
+        112334829348925.99070703983306884765625f);

Review Comment:
   Yes, `double` is tested in TestDecimalToRealDouble::Precision. I added a 
static_assert at the beginning to make it clearer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to