Float和Double值在c中造成混淆
Float and Double value creating confusion in c
我正在运行这个程序。但结果很奇怪。
int main()
{
float a=.8;
if(a < .8)
printf("a is smalln");
else
printf("a is not smalln");
float b=.7;
if(b < .7)
printf("b is smalln");
else
printf("b is not smalln");
return 0;
}
它给我输出——
a不是小
b是小型
为什么不使用0.7f
。0.7
默认为double
,因此我们无法预测其行为
相关文章:
- 当 I2C 值在C++中发生变化时收到通知
- 如何返回实际值(在我的例子中是无符号字符数组)而不是来自 C++ 函数的指针?
- VkSurfaceKHR 指针的值在函数调用后更改,无需任何显式赋值
- 如何在比较时更改集合元素的值(在 c++ 中)?
- "this"指针的值在对象的生存期内是否恒定?
- std::tuple 可以根据其值在编译时/运行时排序吗?
- cppcheck 抱怨危险地使用 c_str(). c_str() 返回的值在此调用后无效
- cpp 检查抱怨危险使用 c_str(). c_str() 返回的值在本次调用后无效,如何解决?
- 为什么这个 x 值在这个循环映射中没有增加?C++
- 为什么双精度引用值在分配给C++中的浮点变量时不会更改
- acos(double) 在 x64 和 x32 Visual Studio 上给出不同的结果
- 将复制构造函数设置为默认值在继承自 QObject 时不起作用
- 返回布尔值在 cocos2dx 的 onTouchBegan() 中是什么意思?
- 如何计算 3d 数组中的索引值在内存中的位置?如何计算字符**中的索引值在内存中的位置?
- 第二个和第二个最终值在 C++ 中混合在二维数组中
- 右移布尔值在C++
- 警告 C6031 返回值在宏扩展中被忽略
- 为什么两个程序中的总和值在最后不同?
- 如何在文件中存储矢量<矢量<double>>值?
- Float和Double值在c中造成混淆