Timmy
Timmy

Reputation: 1

What means conversion from 'double' to 'int', possible loss of data?

I have a question about log form in C. I have defined the variable, which was shown as the below,

double **rx, rr00, perranking;

rx0 = dmatrix(1, PN, 1, M);
perranking = 0;
rr0 = dmatrix(1, PN, 1, M);

for (period = 1; period <= hp; period++) {
    if (rx0[i][j - period] != -99) {
        rr00 += rx0[i][j - period];
        perranking++;
        period++;
    }
    rr0[i][j] = rr00 - double (log(perranking));
}

But, the log form always show that “conversion from 'double' to 'int', possible loss of data”. So how do I adjust my coding, please? Thanks

Upvotes: 0

Views: 332

Answers (1)

0___________
0___________

Reputation: 67476

double value very often will not fit in the integer type.

double x = 10e54;
int y = x;

If you are sure that it will fit just add the explicit cast to suppress the warning

 int y = (int)x;

Upvotes: 1

Related Questions