What is the precision of long double in C++?

后端 未结 2 1074
深忆病人
深忆病人 2020-11-29 06:40

Does anyone know how to find out the precision of long double on a specific platform? I appear to be losing precision after 17 decimal digits, which is the sa

相关标签:
2条回答
  • 2020-11-29 07:02

    You can find out with std::numeric_limits:

    #include <iostream>     // std::cout
    #include <limits>       // std::numeric_limits
    int main(){
        std::cout << std::numeric_limits<long double>::digits10 << std::endl;
    }
    
    0 讨论(0)
  • 2020-11-29 07:03

    You can use <cfloat>. Specifically:

    LDBL_DIG
    
    0 讨论(0)
提交回复
热议问题