Skip to content

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

Open
@tianjixuetu

Description

#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的定义好像不尽如人意,是有什么与那因吗?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions