I have this function:
float calc_nnc(struct ImageWindow *window1, struct ImageWindow *window2) {
double numerator = (double) sum_a_x_b;
double divisor = ( sqrt(sum_a) * sqrt(sum_b) );
double result = numerator / divisor;
float resultf = (float) result;
printf("numerator: %lf, divisor: %lf, result: %lf, resultf: %f\n",
numerator, divisor, result, resultf);
return resultf;
}
printf prints the results that I expect to see:
axb = 1383, a = 1776, b = 4959
numerator: 1383.000000, divisor: 2967.690011, result: 0.466019, resultf: 0.466019
However, when I try to print the result calc_nncin another function:
float nnc_likeness;
unsigned int x, y;
for (y = 0; y <= y_max; y++) {
for (x = 0; x <= x_max; x++) {
set_image_window(&window_big, big, x, y, width, height);
nnc_likeness = calc_nnc(&window_small, &window_big);
printf("likeness: %f\n", nnc_likeness);
}
}
I get garbage:
similarity: 1055824384.000000
That is, I see that the correct values calc_nncare being calculated, but right after that I see a damaged value for nnc_likeness.
Any idea what is going on? Thank!