long double in pow

Why does the i=10 case output wrongly? Shouldn't long double handle it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <iostream>
#include <math.h>
using namespace std;



int main()
{ 
		for (int i = 0; i <= 10; ++i)
	{
		long long int p=static_cast<int>(pow(static_cast<long double>(10), static_cast<long double>(i)));
		cout << p << "\n";
	};

system("pause");
	return 0;
}
closed account (18hRX9L8)
You are casting the return value of pow() to type int instead of long long int... The max numeric limit for an int is only 2147483647 (which is less than 10000000000) while the max numeric limit for an long long int is 9223372036854775807.
Last edited on
Thanks!
closed account (18hRX9L8)
No problem. Don't forget to mark the thread as complete.
Topic archived. No new replies allowed.