Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change convergence condition to DBL_EPSILON.

Previsou coding is bad since comparison between two 0.0 floating points
are not necessarily possible.
  • Loading branch information...
commit d6a57eda9e4908ef5768ad2a5c70bd92d0abb3ae 1 parent ae0411f
@umitanuki authored
Showing with 2 additions and 1 deletion.
  1. +2 −1  kmeans.c
View
3  kmeans.c
@@ -1,5 +1,6 @@
#include "postgres.h"
+#include <float.h>
#include <math.h>
#include "fmgr.h"
@@ -285,7 +286,7 @@ calc_kmeans(myvector inputs, int dim, int N, int k, myvector mean, int *r)
* if all the classification stay, diff must be 0.0,
* which means we can go out!
*/
- if (target == new_target)
+ if (fabs(target - new_target) < DBL_EPSILON)
break;
target = new_target;
}
Please sign in to comment.
Something went wrong with that request. Please try again.