M
Mr Doppino
Hi people,
I would like to submit a problem about double comparison. Here's the code:
struct Cross_point {
int cross_id;
int x, y;
int street_oriz, street_vert;
};
--------------------------------
double nodex, nodey;
Cross_point reference_cross;
***
// Here there are assignments to nodex, nodey, and reference_cross
***
if (nodex == ((double)reference_cross.x))
move_dir = 1;
else if (nodey == ((double)reference_cross.y))
move_dir = 2;
else
fprintf(stderr,"[%f|%f] - cross(%f|%f)\n",nodex, nodey,
double(reference_cross.x), double(reference_cross.y));
-------------------------
The problem is that sometimes even though the values of nodex and
reference_cross.x OR nodey and reference_cross.y are the same I get the
error message. The printing show the values are equal.
Here's the output i get:
[527.000000|601.232221] - cross(527.000000|627.000000)
[527.000000|625.344833] - cross(527.000000|627.000000)
[527.000000|605.427903] - cross(527.000000|627.000000)
[632.289882|627.000000] - cross(622.000000|627.000000)
[639.335527|627.000000] - cross(622.000000|627.000000)
[650.641926|627.000000] - cross(660.000000|627.000000)
[658.736125|627.000000] - cross(660.000000|627.000000)
Thank you
Frank
I would like to submit a problem about double comparison. Here's the code:
struct Cross_point {
int cross_id;
int x, y;
int street_oriz, street_vert;
};
--------------------------------
double nodex, nodey;
Cross_point reference_cross;
***
// Here there are assignments to nodex, nodey, and reference_cross
***
if (nodex == ((double)reference_cross.x))
move_dir = 1;
else if (nodey == ((double)reference_cross.y))
move_dir = 2;
else
fprintf(stderr,"[%f|%f] - cross(%f|%f)\n",nodex, nodey,
double(reference_cross.x), double(reference_cross.y));
-------------------------
The problem is that sometimes even though the values of nodex and
reference_cross.x OR nodey and reference_cross.y are the same I get the
error message. The printing show the values are equal.
Here's the output i get:
[527.000000|601.232221] - cross(527.000000|627.000000)
[527.000000|625.344833] - cross(527.000000|627.000000)
[527.000000|605.427903] - cross(527.000000|627.000000)
[632.289882|627.000000] - cross(622.000000|627.000000)
[639.335527|627.000000] - cross(622.000000|627.000000)
[650.641926|627.000000] - cross(660.000000|627.000000)
[658.736125|627.000000] - cross(660.000000|627.000000)
Thank you
Frank