相关疑难解决方法(0)

对于应该有效的字符串,std :: stod会抛出out_of_range错误

#include <iostream>
#include <cmath>
#include <sstream>
using namespace std;

int main(){
    stringstream ss;
    double ad = 7.63918e-313;
    ss << ad;
    cout<<ss.str()<<endl;
    //you will see that the above double is valid, and maps to the specified string

    //but stod cannot map it back
    stod("7.63918e-313");
    //terminate called after throwing an instance of 'std::out_of_range'
}
Run Code Online (Sandbox Code Playgroud)

在此处运行:https://onlinegdb.com/Sy1MT1iQM

"7.63918e-313"将序列化一个double,但是stod不能反序列化它.这里发生了什么?可能的最小双倍大约是10 ^ -324.

stdlib中是否有一对函数能够可靠地从字符串化中来回映射双精度?不应该吗?

情节变粗.我们有两个奇怪的观察.

  • std::numeric_limits<double>::min() stod也无法解析.

  • std::numeric_limits<double>::min()不是最小的双倍.我们的双倍小,我发现我们可以通过简单地分割min来获得更小的双打,所以这不是我的双重异常或任何东西https://onlinegdb.com/rJvilljQz

我很担心.

c++ floating-point

4
推荐指数
1
解决办法
1224
查看次数

标签 统计

c++ ×1

floating-point ×1