1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #include<iostream> #include <limits> using namespace std; int main() { cout << "\t最大值:" << (numeric_limits<double>::max)(); cout << "\t最小值:" << (numeric_limits<double>::min)() << endl; cout << "long double: \t" << "所占字节数:" << sizeof(long double); cout << "\t最大值:" << (numeric_limits<long double>::max)(); cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl; cout << "float: \t\t" << "所占字节数:" << sizeof(float); cout << "\t最大值:" << (numeric_limits<float>::max)(); cout << "\t最小值:" << (numeric_limits<float>::min)() << endl; return 0; }
|
double: 所占字节数:8 最大值:1.79769e+308 最小值:2.22507e-308
long double: 所占字节数:16 最大值:1.18973e+4932 最小值:3.3621e-4932
float: 所占字节数:4 最大值:3.40282e+38 最小值:1.17549e-38
java呢?
分析几种情况:
真实值 小于 分裂值。 例如 81792.43380 < 81792.4334
真实值 等于 分裂值
真实值 大于 分裂值
miss的情况 走左子树。
舍如方式
通常采用“向最接近的值舍入”的策略。
选择距离 double 值最近的 float 值。如果有多个 float 值与 double 值具有相同的距离,则选择其中的偶数(也称为“向偶数舍入”或“银行家舍入”)。