I can't upload the program to show you what I mean, but the piece of code looks like this:
My program parses the expression so that the '!' would signal a factorial. That number is converted to a double, converted back to an integer, inserted into this function, and the output is converted back to a double, then printed out. (Ignore the lack of error-handling code... it will be there soon.)Code:inline const int Factorial::operate(const int x) const { if (!x) return 1; return x * operate(x-1); }
Positive, integral factorials act the way they should up to 12!. At 13! and upwards, it just fails. (The result is usually around e+09, and it sometimes decreases.) At 34! and upwards, it becomes 0. (Which isn't unusual, given my program's handling of infinity.)
If I have the answer to 12! and multiply it by 13, the answer is correct. I'm assuming that there's a conversion error between a double and an int when the int gets big.
Is that possible? Or am I approaching int_max?