mahesh Rao
mahesh Rao

Reputation: 375

Modulo of long long int number

Hi i tried out a code in c and considering that all variables in the following line of code were of "long long int",

money=(money % 1000000007)+(((2*pow(abs(a[i]-a[j]),k))%1000000007) % 1000000007);

i received an error which states that

error: invalid operands to binary % (have 'double' and 'int') money=(money % 1000000007)+(((2*pow(abs(a[i]-a[j]),k))%1000000007))) % 1000000007); ^

I did not understand what the error meant in this case because i did not use double.Could i get a brief explanation ?

Upvotes: 1

Views: 15245

Answers (2)

Techidiot
Techidiot

Reputation: 1947

% is an integer operator and pow() returns a double. So, you may need to use fmod or fmodf or convert everything to int.

money=(money % 1000000007)+(((2*(long long int)pow(abs(a[i]-a[j]),k))%1000000007))) % 1000000007);

Upvotes: 4

code11
code11

Reputation: 2329

Your problem is with pow. If you look at http://www.cplusplus.com/reference/cmath/pow/ you will see that regardless of what type you give it, it will return either a float or a double.

Try casting the result of pow to an int

Upvotes: 0

Related Questions