适合比较横坐标和纵坐标都是浮点类型的point;
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
typedef struct point
{
float x;
float y;
};
bool pointIsEquation(point* A, point* B)
{
float x = A->x - B->x;
float y = A->y - B->y;
float val = x * x + y * y;
if (abs(val) < 0.000001) // 可通过0.000001的数值调节,来确定比较的精度;
{
return true;
}
return false;
}
void main()
{
point a, b;
a.x = 3.55;
a.y = 2.6798;
b.x = 3.55;
b.y = 2.6799;
printf("Result:%d\n",pointIsEquation(&a, &b));
return;
}
执行结果: