What does this error mean?

        long long mod=1e9+7;
        
        long long ans=n;
        ans=(ans+pow(2, s.size()-1)) % mod;     //s is set

The above code is giving the error

prog.cpp:22:38: error: invalid operands of types ‘__gnu_cxx::__promote_2<int, long unsigned int, double, double>::__type’ {aka ‘double’} and ‘long long int’ to binary ‘operator%’
   22 |         ans=(ans+pow(2, s.size()-1)) % mod;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~
      |                 |                      |
      |                 |                      long long int
      |                 __gnu_cxx::__promote_2<int, long unsigned int, double, double>::__type {aka double}

What does this error mean ?

1 Like

The % operator is not defined for doubles, which is the type of the expression (ans+pow(2, s.size()-1)).

Shortened repro:

#include <iostream>

int main()
{
    double a = 5.2;
    std::cout << (a % 10) << std::endl;
}
  g++ -std=c++17 blah36.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG    -fsanitize=undefined -ftrapv
blah36.cpp: In function ‘int main()’:
blah36.cpp:6:21: error: invalid operands of types ‘double’ and ‘int’ to binary ‘operator%’
    6 |     std::cout << (a % 10) << std::endl;
      |                   ~ ^ ~~
      |                   |   |
      |                   |   int
      |                   double