Actions
Bug #1100
closedRounding error in OFStandard::atof
Start date:
2024-01-12
Due date:
% Done:
100%
Estimated time:
3:00 h
Module:
Operating System:
Compiler:
Description
The following code shows that OFStandard::atof() can produce rounding errors that prevent a lossless round-trip e.g. from DICOM FD to JSON and back.
This sample program shows that OFStandard::atof() produces results that are different from those of std::stod():
#include "dcmtk/dcmdata/dcfilefo.h" int main() { std::string result; result = "14.399999999999999"; OFBool success; double d2 = OFStandard::atof(result.c_str(), &success); std::cout << std::hexfloat << d2 << std::endl; double d3 = std::stod(result); std::cout << std::hexfloat << d3 << std::endl; return 0; }
Reported 2024-01-11 by Mathieu Malaterre <mathieu.malaterre@gmail.com>
Actions