Ý nghĩa chính xác của numeric_limits :: digits10 là gì? Một số câu hỏi liên quan khác trong stackoverflow khiến tôi nghĩ rằng đó là độ chính xác tối đa của một đôi, nhưngÝ nghĩa của numeric_limits <double> :: digit10
- Nguyên mẫu sau bắt đầu làm việc (những thành công là đúng) khi độ chính xác lớn mà 17 (== 2 + numeric_limits :: digits10)
- Với STLPort, readDouble == vô cùng ở cuối; với STL của microsoft, readDouble == 0.0.
- Nguyên mẫu này có ý nghĩa gì không :)?
Đây là nguyên mẫu:
#include <float.h>
#include <limits>
#include <math.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
int main(int argc, const char* argv[]) {
std::ostringstream os;
//int digit10=std::numeric_limits<double>::digits10; // ==15
//int digit=std::numeric_limits<double>::digits; // ==53
os << std::setprecision(17);
os << DBL_MAX;
std::cout << os.str();
std::stringbuf sb(os.str());
std::istream is(&sb);
double readDouble=0.0;
is >> readDouble;
bool success = fabs(DBL_MAX-readDouble)<0.1;
}
liên quan: [chính xác thập phân phao] (http://stackoverflow.com/questions/3310276/decimal-precision-of-floats) và [Is it 6 or 7.22?] (ht tp: //stackoverflow.com/q/30688422/183120). – legends2k