为什么说浮点数的精度远比定点数高??

来源:百度知道 编辑:UC知道 时间:2024/06/07 05:25:19
同上
我是对相同长度情况下的浮点数和定点数来说的~,但是我好像明白了,数很大的时候,浮点数的精度要高一些,可以有更多的位来表示尾数

你说:是1精确,还是1.000000000000000000000001精确?

#include <iostream>
int main () {
std::cout.precision(20);
float a=123.45678901234567890;
double b=123.45678901234567890;
std::cout << a << std::endl;
std::cout << b << std::endl;
return 0;
}
// Xcode 5.1
// Output:
// 123.456787109375
// 123.45678901234568059
// Program ended with exit code: 0