diff options
author | Gunhan Gulsoy <gunan@google.com> | 2017-12-07 21:36:01 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-12-07 21:39:19 -0800 |
commit | 1c4f65b335b29a20511733612be6aed30e79b1a5 (patch) | |
tree | c6d60361abf25a984d4b60385f6718b240b5e233 | |
parent | 233aff82ad661b4792577690044b6a24132a2470 (diff) |
Fix a bug in string to number conversion code.
PiperOrigin-RevId: 178337974
-rw-r--r-- | tensorflow/core/lib/strings/numbers.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tensorflow/core/lib/strings/numbers.cc b/tensorflow/core/lib/strings/numbers.cc index 302a6967e3..f5822fad8e 100644 --- a/tensorflow/core/lib/strings/numbers.cc +++ b/tensorflow/core/lib/strings/numbers.cc @@ -81,10 +81,12 @@ T locale_independent_strtonum(const char* str, const char** endptr) { // number was outside the range, the stringstream sets the fail flag, but // returns the +/-max() value, whereas strto{f,d} functions return +/-INF. if (s.fail()) { - if (result == std::numeric_limits<T>::max()) { + if (result == std::numeric_limits<T>::max() || + result == std::numeric_limits<T>::infinity()) { result = std::numeric_limits<T>::infinity(); s.clear(s.rdstate() & ~std::ios::failbit); - } else if (result == -std::numeric_limits<T>::max()) { + } else if (result == -std::numeric_limits<T>::max() || + result == -std::numeric_limits<T>::infinity()) { result = -std::numeric_limits<T>::infinity(); s.clear(s.rdstate() & ~std::ios::failbit); } |