1. 数据类型
类型 | 定义 | 占位符 |
---|---|---|
长整形 | long | %ld |
长长整形 | long long | %lld |
双浮点型 | double | %lf |
长双浮点型 | long double | %Lf |
sizeof:查看变量或类型的大小
浮点数范围:
输出 | 含义 |
---|---|
inf | 正无穷 |
-inf | 负无穷 |
nan | 不存在 |
小数是否相等,使用最小误差
使用:
#include <math.h>
if(fabs(c-1.2)<0.000001){}
程序:
#include <stdio.h>
#include <math.h>
int main(){
float a = 10.2;
float b = 9;
float c = a - b;
printf("%f - %f = %.7f\n",a,b,c);
if(fabs(c-1.2)<0.000001){
printf("OK\n");
}else{
printf("NG\n");
}
printf("1.0/0.0 = %f\n",1.0/0.0);
}
结果为:
10.200000 - 9.000000 = 1.1999998
OK
1.0/0.0 = inf