zeroshade commented on code in PR #43957:
URL: https://github.com/apache/arrow/pull/43957#discussion_r1767127531
##########
cpp/src/arrow/util/decimal_test.cc:
##########
@@ -1230,65 +1275,72 @@ TYPED_TEST(TestDecimalToRealDouble, LargeValues) {
}
TYPED_TEST(TestDecimalToRealDouble, Precision) {
- // 2**63 + 2**11 (exactly representable in a double's 53 bits of precision)
- CheckDecimalToReal<TypeParam, double>("9223372036854777856", 0,
9.223372036854778e+18);
- CheckDecimalToReal<TypeParam, double>("-9223372036854777856", 0,
- -9.223372036854778e+18);
- // 2**64 - 2**11 (exactly representable in a double)
- CheckDecimalToReal<TypeParam, double>("18446744073709549568", 0,
1.844674407370955e+19);
- CheckDecimalToReal<TypeParam, double>("-18446744073709549568", 0,
- -1.844674407370955e+19);
- // 2**64 + 2**11 (exactly representable in a double)
- CheckDecimalToReal<TypeParam, double>("18446744073709555712", 0,
- 1.8446744073709556e+19);
- CheckDecimalToReal<TypeParam, double>("-18446744073709555712", 0,
- -1.8446744073709556e+19);
- // Almost 10**38 (minus 2**73)
- CheckDecimalToReal<TypeParam,
double>("99999999999999978859343891977453174784", 0,
- 9.999999999999998e+37);
- CheckDecimalToReal<TypeParam,
double>("-99999999999999978859343891977453174784", 0,
- -9.999999999999998e+37);
- CheckDecimalToReal<TypeParam,
double>("99999999999999978859343891977453174784", 10,
- 9.999999999999998e+27);
- CheckDecimalToReal<TypeParam,
double>("-99999999999999978859343891977453174784", 10,
- -9.999999999999998e+27);
- CheckDecimalToReal<TypeParam,
double>("99999999999999978859343891977453174784", -10,
- 9.999999999999998e+47);
- CheckDecimalToReal<TypeParam,
double>("-99999999999999978859343891977453174784", -10,
- -9.999999999999998e+47);
+ if constexpr (TypeParam::kMaxPrecision >= 19) {
+ // 2**63 + 2**11 (exactly representable in a double's 53 bits of precision)
+ CheckDecimalToReal<TypeParam, double>("9223372036854777856", 0,
+ 9.223372036854778e+18);
+ CheckDecimalToReal<TypeParam, double>("-9223372036854777856", 0,
+ -9.223372036854778e+18);
+ // 2**64 - 2**11 (exactly representable in a double)
+ CheckDecimalToReal<TypeParam, double>("18446744073709549568", 0,
+ 1.844674407370955e+19);
+ CheckDecimalToReal<TypeParam, double>("-18446744073709549568", 0,
+ -1.844674407370955e+19);
+ // 2**64 + 2**11 (exactly representable in a double)
+ CheckDecimalToReal<TypeParam, double>("18446744073709555712", 0,
+ 1.8446744073709556e+19);
+ CheckDecimalToReal<TypeParam, double>("-18446744073709555712", 0,
+ -1.8446744073709556e+19);
+
+ // Almost 10**38 (minus 2**73)
+ CheckDecimalToReal<TypeParam,
double>("99999999999999978859343891977453174784", 0,
+ 9.999999999999998e+37);
+ CheckDecimalToReal<TypeParam,
double>("-99999999999999978859343891977453174784", 0,
+ -9.999999999999998e+37);
+ CheckDecimalToReal<TypeParam,
double>("99999999999999978859343891977453174784", 10,
+ 9.999999999999998e+27);
+ CheckDecimalToReal<TypeParam,
double>("-99999999999999978859343891977453174784", 10,
+ -9.999999999999998e+27);
+ CheckDecimalToReal<TypeParam,
double>("99999999999999978859343891977453174784", -10,
+ 9.999999999999998e+47);
+ CheckDecimalToReal<TypeParam,
double>("-99999999999999978859343891977453174784", -10,
+ -9.999999999999998e+47);
+ }
// Integers are always exact
auto scale = TypeParam::kMaxScale - 1;
std::string seven = "7.";
seven.append(scale, '0');
CheckDecimalToReal<TypeParam, double>(seven, scale, 7.0);
CheckDecimalToReal<TypeParam, double>("-" + seven, scale, -7.0);
-
- CheckDecimalToReal<TypeParam,
double>("99999999999999999999.0000000000000000", 16,
- 99999999999999999999.0);
- CheckDecimalToReal<TypeParam,
double>("-99999999999999999999.0000000000000000", 16,
- -99999999999999999999.0);
+ if constexpr (TypeParam::kMaxPrecision >= 20) {
+ CheckDecimalToReal<TypeParam,
double>("99999999999999999999.0000000000000000", 16,
+ 99999999999999999999.0);
+ CheckDecimalToReal<TypeParam,
double>("-99999999999999999999.0000000000000000", 16,
+ -99999999999999999999.0);
+ }
// Small fractions are within one ULP
CheckDecimalToRealWithinOneULP<TypeParam, double>("9999999.9", 1, 9999999.9);
CheckDecimalToRealWithinOneULP<TypeParam, double>("-9999999.9", 1,
-9999999.9);
- CheckDecimalToRealWithinOneULP<TypeParam, double>("9999999.999999999999999",
15,
- 9999999.999999999999999);
- CheckDecimalToRealWithinOneULP<TypeParam,
double>("-9999999.999999999999999", 15,
- -9999999.999999999999999);
-
- // Large fractions are within 2^-52
- constexpr double epsilon = 2.220446049250313080847263336181640625e-16; //
2^-52
- CheckDecimalToRealWithinEpsilon<TypeParam, double>(
- "112334829348925.99070703983306884765625", 23, epsilon,
- 112334829348925.99070703983306884765625);
- CheckDecimalToRealWithinEpsilon<TypeParam, double>(
- "1.987748987892758765582589910934859345", 36, epsilon,
- 1.987748987892758765582589910934859345);
+ if constexpr (TypeParam::kMaxPrecision >= 23) {
+ CheckDecimalToRealWithinOneULP<TypeParam,
double>("9999999.999999999999999", 15,
+ 9999999.999999999999999);
+ CheckDecimalToRealWithinOneULP<TypeParam,
double>("-9999999.999999999999999", 15,
+
-9999999.999999999999999);
+ // Large fractions are within 2^-52
+ constexpr double epsilon = 2.220446049250313080847263336181640625e-16; //
2^-52
+ CheckDecimalToRealWithinEpsilon<TypeParam, double>(
+ "112334829348925.99070703983306884765625", 23, epsilon,
+ 112334829348925.99070703983306884765625);
+ CheckDecimalToRealWithinEpsilon<TypeParam, double>(
+ "1.987748987892758765582589910934859345", 36, epsilon,
+ 1.987748987892758765582589910934859345);
+ }
}
#endif // __MINGW32__
-TEST(Decimal128Test, TestFromBigEndian) {
+TEST(Decimal32Test, TestFromBigEndian) {
Review Comment:
added generic versions for most of them. the LeftShift/RightShift and Negate
tests are sufficiently different in their values that it's harder to make them
generic
--
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]