Weird output?

closed account (LN7oGNh0)
I wrote a small program that inputs a number n. then does 2 to the power of n. I realized afterwards that I did not include the 'maths' header but it still worked? (using microsoft visual C++ 2010 express). Heres the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

using namespace std;

int main()
{
	float input;
	cin >> input;
	cout << pow(2, input);
	cin.ignore();
	cin.get();
	return 0;
}


when i typed 78954675946789.58654, (to raise 2 to this power) I got this output:

1.#INF


Anyone understand why this would happen?
I was just wondering.

Thanks.
That's because floats, like any type has some fixed precision. You can only store a finite amount of numbers on a finite amount of memory. Unlike, say, int, floats don't wrap around. They have special values to mean "infinity" or "not a number".

This thread shouldn't be in lounge though...
closed account (LN7oGNh0)
ok thank you.
Sorry...
Topic archived. No new replies allowed.