代码之家  ›  专栏  ›  技术社区  ›  Bill the Lizard

C++中长双倍的精度是多少?

  •  22
  • Bill the Lizard  · 技术社区  · 17 年前

    有人知道如何找出 long double 在特定的平台上?我似乎在小数点后17位失去了精确性,这与我刚使用 double . 我希望得到更多,因为 双重的 在我的平台上用8个字节表示,而 长双倍 是12字节。

    在你问之前,这是为项目欧拉,所以是的,我 需要超过17位数字。:)

    编辑: 谢谢你的快速回复。我刚确认我只能用 长双倍 在我的系统上。

    2 回复  |  直到 9 年前
        1
  •  33
  •   WhiZTiM    9 年前

    你可以用 std::numeric_limits :

    #include <iostream>     // std::cout
    #include <limits>       // std::numeric_limits
    int main(){
        std::cout << std::numeric_limits<long double>::digits10 << std::endl;
    }
    
        2
  •  5
  •   Bill the Lizard    17 年前

    你可以使用 <cfloat> . 明确地:

    LDBL_DIG