浮点数比较

第一种

#define EPS 1e-6
if(((a - b > - EPS) && ((a - b) < EPS)))

第二种进行内存比较

	float test = 100.1f;
	char buffer[sizeof(float)+1] = {};
    //将内存数据内存拷贝到字符数组
	memcpy(buffer, &test, sizeof(float));

	float test2 = 100.1f;
	char buffer2[sizeof(float)+1] = {};
    //将内存数据拷贝到字符数组
	memcpy(buffer2, &test, sizeof(float));

	int ret = strcmp(buffer, buffer2);
	if (strcmp(buffer, buffer2) == 0)
	{
		printf("相等\n");
	}
    //从内存中取出数据
    memcpy(&test2, buffer, sizeof(float));

你可能感兴趣的:(c,学一点,随笔记,c语言)