Commit 72e293a2 authored by Thomas Van Lenten's avatar Thomas Van Lenten Committed by GitHub

Merge pull request #3240 from thomasvl/float_fun

Raise the number of digits used for floats.
parents 5729cf77 dd19b876
...@@ -759,6 +759,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, ...@@ -759,6 +759,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
}); });
TestValidDataForType(FieldDescriptor::TYPE_FLOAT, { TestValidDataForType(FieldDescriptor::TYPE_FLOAT, {
{flt(0.1), "0.1"}, {flt(0.1), "0.1"},
{flt(1.00000075e-36), "1.00000075e-36"},
{flt(3.402823e+38), "3.402823e+38"}, // 3.40282347e+38 {flt(3.402823e+38), "3.402823e+38"}, // 3.40282347e+38
{flt(1.17549435e-38f), "1.17549435e-38"} {flt(1.17549435e-38f), "1.17549435e-38"}
}); });
......
...@@ -199,5 +199,6 @@ Required.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput ...@@ -199,5 +199,6 @@ Required.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput
Required.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput Required.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput
Required.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput Required.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput
Required.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput Required.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput
Required.ProtobufInput.ValidDataRepeated.FLOAT.JsonOutput
Required.TimestampProtoInputTooLarge.JsonOutput Required.TimestampProtoInputTooLarge.JsonOutput
Required.TimestampProtoInputTooSmall.JsonOutput Required.TimestampProtoInputTooSmall.JsonOutput
...@@ -1401,7 +1401,7 @@ char* FloatToBuffer(float value, char* buffer) { ...@@ -1401,7 +1401,7 @@ char* FloatToBuffer(float value, char* buffer) {
float parsed_value; float parsed_value;
if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) { if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) {
int snprintf_result = int snprintf_result =
snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG+2, value); snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG+3, value);
// Should never overflow; see above. // Should never overflow; see above.
GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize); GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment