binapi icon indicating copy to clipboard operation
binapi copied to clipboard

double_type会造成精度问题,感觉还是直接使用double会比较好

Open tianjixuetu opened this issue 1 year ago • 1 comments

#include <iostream>
#include <ctime>
#include <iomanip>
#include <limits>
#include <cstring>
#include <string>
#include <cassert>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/number.hpp>

using double_type = boost::multiprecision::number<
        boost::multiprecision::cpp_dec_float<8>,
        boost::multiprecision::et_off
>;

int main() {
    double_type value1("99999999.27"); 
    std::cout << "value1 = " << value1 << std::endl; // value1 = 1e+8

    double_type value3 = 99999999.27; 
    std::cout << "value3 = " << value3 << std::endl; // value1 = 1e+8

    double_type value2 = 0.0000000007379;
    std::cout << "value2 = " << value2 << std::endl;

    double_type value4 = 1.23456789123456789; // 大数
    std::cout << "value4 = " << value4 << std::endl; // value5 = 1.23457

    double_type value5("1.23456789123456789"); // 大数
    std::cout << "value5 = " << value5 << std::endl; // value5 = 1.23457

    return 0;
}

double_type的定义好像不尽如人意,是有什么与那因吗?

tianjixuetu avatar Mar 12 '24 12:03 tianjixuetu

could you translate to english please?

niXman avatar Mar 03 '25 21:03 niXman