摘要:
前几天去面试,被问到怎么比较两个浮点数的大小,当时只说了个大概,看得出来面试官不是太满意,回来特意查了一下,在MSDN上发现了比较浮点数是否相等的不错的方法:// Initialize two doubles with apparently identical valuesdouble double1 = .33333;double double2 = (double) 1/3;// Define the tolerance for variation in their valuesdouble difference = double1 * .0001;// Compare the value 阅读全文