aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpython/google/protobuf/text_format.py2
-rw-r--r--src/google/protobuf/compiler/python/python_generator.cc16
2 files changed, 9 insertions, 9 deletions
diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py
index 2def19c2..428e8c55 100755
--- a/python/google/protobuf/text_format.py
+++ b/python/google/protobuf/text_format.py
@@ -45,7 +45,7 @@ __all__ = [ 'MessageToString', 'PrintMessage', 'PrintField',
# Infinity and NaN are not explicitly supported by Python pre-2.6, and
# float('inf') does not work on Windows (pre-2.6).
-_INFINITY = float('1e10000')
+_INFINITY = 1e10000 # overflows, thus will actually be infinity.
_NAN = _INFINITY * 0
diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc
index 2f7d0981..fae83a37 100644
--- a/src/google/protobuf/compiler/python/python_generator.cc
+++ b/src/google/protobuf/compiler/python/python_generator.cc
@@ -169,14 +169,14 @@ string StringifyDefaultValue(const FieldDescriptor& field) {
double value = field.default_value_double();
if (value == numeric_limits<double>::infinity()) {
// Python pre-2.6 on Windows does not parse "inf" correctly. However,
- // parsing a number that is too big for a double will return infinity.
- return "float('1e10000')";
+ // a numeric literal that is too big for a double will become infinity.
+ return "1e10000";
} else if (value == -numeric_limits<double>::infinity()) {
// See above.
- return "float('-1e10000')";
+ return "-1e10000";
} else if (value != value) {
// infinity * 0 = nan
- return "(float('1e10000') * 0)";
+ return "(1e10000 * 0)";
} else {
return SimpleDtoa(value);
}
@@ -185,14 +185,14 @@ string StringifyDefaultValue(const FieldDescriptor& field) {
float value = field.default_value_float();
if (value == numeric_limits<float>::infinity()) {
// Python pre-2.6 on Windows does not parse "inf" correctly. However,
- // parsing a number that is too big for a double will return infinity.
- return "float('1e10000')";
+ // a numeric literal that is too big for a double will become infinity.
+ return "1e10000";
} else if (value == -numeric_limits<float>::infinity()) {
// See above.
- return "float('-1e10000')";
+ return "-1e10000";
} else if (value != value) {
// infinity - infinity = nan
- return "(float('1e10000') - float('1e10000'))";
+ return "(1e10000 * 0)";
} else {
return SimpleFtoa(value);
}