Doubt in pow function output

Hi everyone, I executed pow() within for loop. while executing this output in integer data type. I get a output like resultant value -1.I do not know Why I am getting this output like this. Can anyone clarify my doubt. Below I attached my program.

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);

int powValue;
for(int i=1;i<8;i++){
  powValue=(int)pow(2,i);
  Serial.println(powValue);
}
}

void loop() {
  // put your main code here, to run repeatedly:

}

OUTPUT will be,
2
3
7
15
31
63
127

Why use a floating point function, to calculate integer powers of integers?

for(int i=1;i<8;i++){
  int powValue = 1 << i;
  Serial.println(powValue);
}
void setup() {
  Serial.begin(250000);
  int powValue;
  float powValueF;
  for (int i = 1; i < 8; i++) {
    powValueF = pow(2, i);
    powValue = (int)powValueF;
    Serial.print(F("pow(2, "));
    Serial.print(i);
    Serial.print(F(") = "));
    Serial.print(powValueF, 6);
    Serial.print(F(", which gives after integer truncation "));
    Serial.println(powValue);
  }
}
void loop() {}
pow(2, 1) = 2.000000, which gives after integer truncation 2
pow(2, 2) = 4.000000, which gives after integer truncation 3
pow(2, 3) = 7.999998, which gives after integer truncation 7
pow(2, 4) = 15.999997, which gives after integer truncation 15
pow(2, 5) = 31.999988, which gives after integer truncation 31
pow(2, 6) = 63.999977, which gives after integer truncation 63
pow(2, 7) = 127.999954, which gives after integer truncation 127

Thank you for your clarification.

The other thing to consider is that in using int you're inviting negative numbers, as soon as you overflow 15 bits.

the built-in function round() is useful when converting floats to int - the default cast truncates towards
zero which is not always what you want.

Adding 0.5 before casting also avoids the truncate and rounds.

Whandall:
Adding 0.5 before casting also avoids the truncate and rounds.

No, it fails for negative values completely.

In the context of pow(2,x) there are no negative values.