Mercurial > hg > orthanc
diff Core/DicomParsing/DicomWebJsonVisitor.cpp @ 3312:b88937ef597b
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 26 Feb 2019 16:42:21 +0100 |
parents | 4be505c2ac56 |
children | eb57b7cd5f21 |
line wrap: on
line diff
--- a/Core/DicomParsing/DicomWebJsonVisitor.cpp Tue Feb 26 13:10:40 2019 +0100 +++ b/Core/DicomParsing/DicomWebJsonVisitor.cpp Tue Feb 26 16:42:21 2019 +0100 @@ -324,16 +324,25 @@ Json::Value DicomWebJsonVisitor::FormatDouble(double value) { - long long a = boost::math::llround<double>(value); + try + { + long long a = boost::math::llround<double>(value); - double d = fabs(value - static_cast<double>(a)); + double d = fabs(value - static_cast<double>(a)); - if (d <= std::numeric_limits<double>::epsilon() * 100.0) + if (d <= std::numeric_limits<double>::epsilon() * 100.0) + { + return FormatInteger(a); + } + else + { + return Json::Value(value); + } + } + catch (boost::math::rounding_error&) { - return FormatInteger(a); - } - else - { + // Can occur if "long long" is too small to receive this value + // (e.g. infinity) return Json::Value(value); } }