您可以查詢the numeric_limits
class template或<cfloat>
macros點,可以準確後得到的顯著小數位數顯示:
#include <limits>
#include <iostream>
int main() {
std::cout << std::numeric_limits<float>::digits10 << std::endl;
std::cout << FLOAT_DIG << std::endl;
// 6
std::cout << std::numeric_limits<double>::digits10 << std::endl;
std::cout << DBL_DIG << std::endl;
// 15
std::cout << std::numeric_limits<long double>::digits10 << std::endl;
std::cout << LDBL_DIG << std::endl;
// 18
}
在x86,一個long double
通常專賣店爲extended precision格式(其中只有80位,而不是96位;由於對齊,sizeof被填充到12個字節)。
請注意,數字的數量遠遠小於101.你應該找出一個算法來計算第n個根到任意精度。
大多數系統中的浮點數由[IEEE浮點格式](https://en.wikipedia.org/wiki/IEEE_floating_point)表示。 –
80位,而不是96,64位存儲尾數。因此它可以表示pow(2,64)= 1.8E19不同的值。所以不要超過19位重要的十進制數字。在對數值進行任何數學運算時,您會很快失去一個數值,只需將數值從十進制轉換爲二進制數,例如乘以並轉換回小數就足夠了,因爲該值需要四捨五入。所以用18作爲實用價值。 –