C++ precision of numbers and truncation with fstream

后端 未结 2 653
南笙
南笙 2021-01-20 02:40

I have a file.txt with hundreds of numbers. They have many digits (max 20) after the point and I need to get them all without truncation, otherwise they introduce errors in

2条回答
  •  借酒劲吻你
    2021-01-20 03:06

    std::numeric_limits::min std::numeric_limits::digits10 can tell you what your target's actual precision is for long double.

    If you find that it's insufficient to represent your data, you probably want arbitrary precision. There are a couple of arbitrary precision number libraries you can use, none of which are standard in C++.

    • boost::multiprecision
    • GNU MP
    • MPFR

提交回复
热议问题