Ok, can someone explain why this set of code is doing this. Here is an excerpt from a test driver that calls a distance between two points function:
(block 1) cout << distance(0,0,2,0) << endl << distance(1,sqrt(3),2,0) << endl
<< distance(1,sqrt(3),0,0);
(block 2) cout << endl << (distance(1,sqrt(3), 0, 0) == distance(2,0, 1, sqrt(3))) <<
endl << (distance(0, 0, 2, 0) == distance(1, sqrt(3),2, 0)) << endl
<< (distance(1,sqrt(3), 0, 0) == distance(0, 0, 2, 0));
When block one is executed it prints:
2
2
2
However when block 2 is executed it prints:
1
0
0
However the last two should be true (1). To see what was going on I insterted a cout << setprecision() above block 1 and gradually increased it. As soon as I set the precision to 17 the first block's output changed to:
2
1.9999999........
1.9999999........
Is there some way that I can inform my distance function to only check to the 16th decimal place or below so that I can get those three points to equal each other?
(block 1) cout << distance(0,0,2,0) << endl << distance(1,sqrt(3),2,0) << endl
<< distance(1,sqrt(3),0,0);
(block 2) cout << endl << (distance(1,sqrt(3), 0, 0) == distance(2,0, 1, sqrt(3))) <<
endl << (distance(0, 0, 2, 0) == distance(1, sqrt(3),2, 0)) << endl
<< (distance(1,sqrt(3), 0, 0) == distance(0, 0, 2, 0));
When block one is executed it prints:
2
2
2
However when block 2 is executed it prints:
1
0
0
However the last two should be true (1). To see what was going on I insterted a cout << setprecision() above block 1 and gradually increased it. As soon as I set the precision to 17 the first block's output changed to:
2
1.9999999........
1.9999999........
Is there some way that I can inform my distance function to only check to the 16th decimal place or below so that I can get those three points to equal each other?