comparison 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
comparison
equal deleted inserted replaced
3311:f2f8aa6f78aa 3312:b88937ef597b
322 } 322 }
323 323
324 324
325 Json::Value DicomWebJsonVisitor::FormatDouble(double value) 325 Json::Value DicomWebJsonVisitor::FormatDouble(double value)
326 { 326 {
327 long long a = boost::math::llround<double>(value); 327 try
328 328 {
329 double d = fabs(value - static_cast<double>(a)); 329 long long a = boost::math::llround<double>(value);
330 330
331 if (d <= std::numeric_limits<double>::epsilon() * 100.0) 331 double d = fabs(value - static_cast<double>(a));
332 { 332
333 return FormatInteger(a); 333 if (d <= std::numeric_limits<double>::epsilon() * 100.0)
334 } 334 {
335 else 335 return FormatInteger(a);
336 { 336 }
337 else
338 {
339 return Json::Value(value);
340 }
341 }
342 catch (boost::math::rounding_error&)
343 {
344 // Can occur if "long long" is too small to receive this value
345 // (e.g. infinity)
337 return Json::Value(value); 346 return Json::Value(value);
338 } 347 }
339 } 348 }
340 349
341 350