Raise the number of digits used for floats.

About 1.5% of all IEEE754 single-precision numbers require nine
decimal digits to represent accurately.
pull/3240/head
Thomas Van Lenten 8 years ago
parent 91bf623aa1
commit dd19b876d4
  1. 1
      conformance/conformance_test.cc
  2. 1
      conformance/failure_list_ruby.txt
  3. 2
      src/google/protobuf/stubs/strutil.cc

@ -759,6 +759,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
});
TestValidDataForType(FieldDescriptor::TYPE_FLOAT, {
{flt(0.1), "0.1"},
{flt(1.00000075e-36), "1.00000075e-36"},
{flt(3.402823e+38), "3.402823e+38"}, // 3.40282347e+38
{flt(1.17549435e-38f), "1.17549435e-38"}
});

@ -199,5 +199,6 @@ Required.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput
Required.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput
Required.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput
Required.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput
Required.ProtobufInput.ValidDataRepeated.FLOAT.JsonOutput
Required.TimestampProtoInputTooLarge.JsonOutput
Required.TimestampProtoInputTooSmall.JsonOutput

@ -1401,7 +1401,7 @@ char* FloatToBuffer(float value, char* buffer) {
float parsed_value;
if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) {
int snprintf_result =
snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG+2, value);
snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG+3, value);
// Should never overflow; see above.
GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);

Loading…
Cancel
Save