diff --git a/cpp/src/arrow/vendored/double-conversion/double-conversion.cc b/cpp/src/arrow/vendored/double-conversion/double-conversion.cc index d287b44c5d439..8defb333cb9a5 100644 --- a/cpp/src/arrow/vendored/double-conversion/double-conversion.cc +++ b/cpp/src/arrow/vendored/double-conversion/double-conversion.cc @@ -85,6 +85,15 @@ void DoubleToStringConverter::CreateExponentialRepresentation( ASSERT(length != 0); result_builder->AddCharacter(decimal_digits[0]); + /* If the mantissa of the scientific notation representation is an integer number, + * the EMIT_TRAILING_DECIMAL_POINT flag will add a '.' character at the end of the + * representation: + * - With EMIT_TRAILING_DECIMAL_POINT enabled -> 0.0009 => 9.E-4 + * - With EMIT_TRAILING_DECIMAL_POINT disabled -> 0.0009 => 9E-4 + * + * If the mantissa is an integer and the EMIT_TRAILING_ZERO_AFTER_POINT flag is enabled + * it will add a '0' character at the end of the mantissa representation. Note that that + * flag depends on EMIT_TRAILING_DECIMAL_POINT flag be enabled.*/ if(length == 1){ if ((flags_ & EMIT_TRAILING_DECIMAL_POINT) != 0) { result_builder->AddCharacter('.'); diff --git a/cpp/src/arrow/vendored/double-conversion/double-conversion.h b/cpp/src/arrow/vendored/double-conversion/double-conversion.h index 6dbc0997c617f..9dc3ebd8dfda3 100644 --- a/cpp/src/arrow/vendored/double-conversion/double-conversion.h +++ b/cpp/src/arrow/vendored/double-conversion/double-conversion.h @@ -104,6 +104,17 @@ class DoubleToStringConverter { // ToPrecision(230.0, 2) -> "230" // ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT. // ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT. + // + // When converting numbers to scientific notation representation, if the mantissa of + // the representation is an integer number, the EMIT_TRAILING_DECIMAL_POINT flag will + // add a '.' character at the end of the representation: + // - With EMIT_TRAILING_DECIMAL_POINT enabled -> 0.0009 => 9.E-4 + // - With EMIT_TRAILING_DECIMAL_POINT disabled -> 0.0009 => 9E-4 + // + // If the mantissa is an integer and the EMIT_TRAILING_ZERO_AFTER_POINT flag is enabled + // it will add a '0' character at the end of the mantissa representation. Note that that + // flag depends on EMIT_TRAILING_DECIMAL_POINT flag be enabled. + // - With EMIT_TRAILING_ZERO_AFTER_POINT enabled -> 0.0009 => 9.0E-4 DoubleToStringConverter(int flags, const char* infinity_symbol, const char* nan_symbol, diff --git a/cpp/src/gandiva/formatting_utils.h b/cpp/src/gandiva/formatting_utils.h index 257d3077d494a..0f9bef68a7e30 100644 --- a/cpp/src/gandiva/formatting_utils.h +++ b/cpp/src/gandiva/formatting_utils.h @@ -39,11 +39,21 @@ class FloatToStringGdvMixin using arrow::internal::FloatToStringFormatterMixin< ARROW_TYPE>::FloatToStringFormatterMixin; + // The mixin is a modified version of the existent FloatToStringFormatterMixin, but + // it defines some specific parameters in the FloatToStringFormatterMixin to cast + // the float numbers to string using the same patterns like Java. + // + // The Java real numbers are represented in two ways following these rules: + //- If the number is greater or equals than 10^7 and less than 10^(-3) + // it will be represented using scientific notation, e.g: + // - 0.000012 -> 1.2E-5 + // - 10000002.3 -> 1.00000023E7 + //- If the numbers are between that interval above, they are showed as is. explicit FloatToStringGdvMixin(const std::shared_ptr& = NULLPTR) : arrow::internal::FloatToStringFormatterMixin( DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT | DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT, - "inf", "nan", 'E', -3, 7, 3, 1) {} + "Infinity", "NaN", 'E', -3, 7, 3, 1) {} }; template <>