小编Gab*_*fer的帖子

浮点数等式检查

使用以下代码,

#include <stdio.h>

int main(void){
  float x;
  x=(float)3.3==3.3;
  printf("%f",x);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出为0.00000

但当数字3.3被3.5替换时,

#include <stdio.h>

int main(void){
  float x;
  x=(float)3.5==3.5;
  printf("%f",x);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出为1.0000

为什么输出有差异?

c floating-point

4
推荐指数
2
解决办法
4042
查看次数

标签 统计

c ×1

floating-point ×1