Project

General

Profile

Actions

Bug #1100

closed

Rounding error in OFStandard::atof

Added by Marco Eichelberg over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Category:
-
Target version:
-
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 <>

Actions #1

Updated by Marco Eichelberg over 1 year ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100
  • Estimated time set to 3:00 h

Closed by commit #ecbf61cb7.

Actions

Also available in: Atom PDF