Skip to content

Commit 302139c

Browse files
Add emit trailing point tests
1 parent efb94b9 commit 302139c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

cpp/src/arrow/vendored/double-conversion/double-conversion.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ void DoubleToStringConverter::CreateExponentialRepresentation(
8484
StringBuilder* result_builder) const {
8585
ASSERT(length != 0);
8686
result_builder->AddCharacter(decimal_digits[0]);
87-
if (length != 1) {
87+
88+
if(length == 1){
89+
if ((flags_ & EMIT_TRAILING_DECIMAL_POINT) != 0) {
90+
result_builder->AddCharacter('.');
91+
}
92+
if ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT) != 0) {
93+
result_builder->AddCharacter('0');
94+
}
95+
} else {
8896
result_builder->AddCharacter('.');
8997
result_builder->AddSubstring(&decimal_digits[1], length-1);
9098
}

cpp/src/gandiva/gdv_function_stubs_test.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ TEST(TestGdvFnStubs, TestCastVARCHARFromFloat) {
234234
EXPECT_FALSE(ctx.has_error());
235235

236236
out_str = gdv_fn_castVARCHAR_float32_int64(ctx_ptr, 0.00001f, 100, &out_len);
237-
EXPECT_EQ(std::string(out_str, out_len), "1E-5");
237+
EXPECT_EQ(std::string(out_str, out_len), "1.0E-5");
238238
EXPECT_FALSE(ctx.has_error());
239239

240240
out_str = gdv_fn_castVARCHAR_float32_int64(ctx_ptr, 0.00099999f, 100, &out_len);
@@ -245,6 +245,10 @@ TEST(TestGdvFnStubs, TestCastVARCHARFromFloat) {
245245
EXPECT_EQ(std::string(out_str, out_len), "0.0");
246246
EXPECT_FALSE(ctx.has_error());
247247

248+
out_str = gdv_fn_castVARCHAR_float32_int64(ctx_ptr, 10.00000f, 100, &out_len);
249+
EXPECT_EQ(std::string(out_str, out_len), "10.0");
250+
EXPECT_FALSE(ctx.has_error());
251+
248252
// test with required length less than actual buffer length
249253
out_str = gdv_fn_castVARCHAR_float32_int64(ctx_ptr, 1.2345f, 3, &out_len);
250254
EXPECT_EQ(std::string(out_str, out_len), "1.2");
@@ -265,7 +269,7 @@ TEST(TestGdvFnStubs, TestCastVARCHARFromDouble) {
265269
EXPECT_FALSE(ctx.has_error());
266270

267271
out_str = gdv_fn_castVARCHAR_float64_int64(ctx_ptr, 0.00001, 100, &out_len);
268-
EXPECT_EQ(std::string(out_str, out_len), "1E-5");
272+
EXPECT_EQ(std::string(out_str, out_len), "1.0E-5");
269273
EXPECT_FALSE(ctx.has_error());
270274

271275
out_str = gdv_fn_castVARCHAR_float32_int64(ctx_ptr, 0.00099999f, 100, &out_len);
@@ -276,6 +280,10 @@ TEST(TestGdvFnStubs, TestCastVARCHARFromDouble) {
276280
EXPECT_EQ(std::string(out_str, out_len), "0.0");
277281
EXPECT_FALSE(ctx.has_error());
278282

283+
out_str = gdv_fn_castVARCHAR_float64_int64(ctx_ptr, 10.0000000000, 100, &out_len);
284+
EXPECT_EQ(std::string(out_str, out_len), "10.0");
285+
EXPECT_FALSE(ctx.has_error());
286+
279287
// test with required length less than actual buffer length
280288
out_str = gdv_fn_castVARCHAR_float64_int64(ctx_ptr, 1.2345, 3, &out_len);
281289
EXPECT_EQ(std::string(out_str, out_len), "1.2");

0 commit comments

Comments
 (0)