aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/framework
diff options
context:
space:
mode:
authorGravatar Yong Tang <yong.tang.github@outlook.com>2018-09-01 01:55:43 +0000
committerGravatar Yong Tang <yong.tang.github@outlook.com>2018-09-04 06:50:34 +0000
commita8a0ec4a2eaf37c853afe410964978715c3d02bb (patch)
tree2e0a6f564e5dceaa568fd150a6114ef71ad2b4ad /tensorflow/python/framework
parentce9e5b035b32ef02cd7d10f6ffdd27cc2a75664d (diff)
Add precision to match the existing behavior.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Diffstat (limited to 'tensorflow/python/framework')
-rw-r--r--tensorflow/python/framework/python_op_gen_internal.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/tensorflow/python/framework/python_op_gen_internal.cc b/tensorflow/python/framework/python_op_gen_internal.cc
index 8ddd1e6432..dafaf2fd3a 100644
--- a/tensorflow/python/framework/python_op_gen_internal.cc
+++ b/tensorflow/python/framework/python_op_gen_internal.cc
@@ -16,6 +16,8 @@ limitations under the License.
#include "tensorflow/python/framework/python_op_gen_internal.h"
#include <stdio.h>
+#include <float.h>
+#include <iomanip>
#include <sstream>
#include <unordered_map>
#include "tensorflow/core/framework/api_def.pb.h"
@@ -435,9 +437,11 @@ string AttrValueToPython(const string& type, const AttrValue& value,
if (std::isnan(value.f()) || std::isinf(value.f())) {
return strings::StrCat("float('", value.f(), "')");
} else {
+ // Use locale-independent conversion.
+ static_assert(FLT_DIG < 10, "FLT_DIG is too big");
std::ostringstream s;
s.imbue(std::locale::classic());
- s << value.f();
+ s << std::setprecision(FLT_DIG) << value.f();
return s.str();
}
} else if (type == "bool") {