What is the meaning of numeric_limitslt;doublegt;::digits10(numeric_limitsdouble::digits10是什么意思)
问题描述
numeric_limits::digits10 的确切含义是什么?stackoverflow 中的一些其他相关问题让我认为它是双精度的最大精度,但是
What is the precise meaning of numeric_limits::digits10? Some other related questions in stackoverflow made me think it is the maximum precision of a double, but
- 当精度大于 17 ( == 2+numeric_limits::digits10) 时,以下原型开始工作(成功为真)
- 使用STLPort,最后readDouble==infinity;使用微软的 STL,readDouble == 0.0.
- 这个原型有什么意义吗:)?
这是原型:
#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;
}
推荐答案
numeric_limits::digits10
是可以不丢失的小数位数.
numeric_limits::digits10
is the number of decimal digits that can be held without loss.
例如 numeric_limits
是 2.这意味着无符号字符可以保持 0..99 而不会丢失.如果是 3,它可以容纳 0..999,但众所周知,它只能容纳 0..255.
For example numeric_limits<unsigned char>::digits10
is 2. This means that an unsigned char can hold 0..99 without loss. If it were 3 it could hold 0..999, but as we all know it can only hold 0..255.
本手册页有一个浮点数示例,其中(缩短时)表明
This manual page has an example for floating point numbers, which (when shortened) shows that
cout << numeric_limits<float>::digits10 <<endl;
float f = (float)99999999; // 8 digits
cout.precision ( 10 );
cout << "The float is; " << f << endl;
印刷品
6
The float is; 100000000
这篇关于numeric_limits<double>::digits10是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:numeric_limits<double>::digits10是什么意思


基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01