我想避免除以零,所以我有一个if语句:
float number;
//........
if (number > 0.000000000000001) 
  number = 1/number;我可以安全地使用多小的值来代替0.000000000000001
发布于 2013-08-14 16:22:45
对于数字类型,T std::numeric_limits提供您需要的任何东西。例如,您可以这样做,以确保min_invertible之上的任何内容都具有有限的倒数:
float max_float = std::numeric_limits<float>::max(); 
float min_float = std::numeric_limits<float>::min(); // or denorm_min()
float min_invertible = (max_float*min_float > 1.0f )? min_float : 1.0f/max_float;https://stackoverflow.com/questions/18234311
复制相似问题