Skip to content

Decimal precision truncated when serialize/deserialize std::vector<double> container #417

@zhoupengwei

Description

@zhoupengwei

Hi author, I found that the std::vector lost precision during the process of deserializing, As the following sample code:

ryml::Tree tree;

  {
    std::vector<double> test_vec{1.23234412342131234,
                                 2.12323123143434237,
                                 3.67847983572591234};
    ryml::NodeRef root = tree.rootref();
    root |= ryml::SEQ;
    root << test_vec;
  }

  {
    ryml::ConstNodeRef root = tree.crootref();
    std::vector<double> test_vec;
    root >> test_vec;
    for (const auto& elem : test_vec) {
      std::cout << "elem " << elem << std::endl;
    }
  }

The program will output:
elem 1.23234
elem 2.12323
elem 3.67848

How can I avoid losing numerical accuracy ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions