Let's keep that as one option although I still didn't understand what the template example does [more importantly how it works, I get that it finds factorial before hand but where is the input? |
The input is where you use it in your code.
and what you meant by 2x3 evaluates to 6.. that is multiplication I didn't get the link. If that is supposed to be 3! then I have told you that I want to find a way that avoids multiplication. |
I demonstrated that the compiler has a precedent of doing arithmetic rather than deferring it to a run-time calculation. I showed the source input in C and the compiled output in assembler.
I then went on to demonstrate how operations other than basic arithmetic can be generated at compile time, using factorial as the example.
Anyways for large numbers like 29 you cannot rely on compile time processing either. One it is going to be time consuming and inefficient, Two even long long int cannot store such large numbers (like factorial of 29!). |
I agree 29! is a large number. That aside, I don't know what you mean.
But if we wrote a table for say subtraction of factorials then we could find the value of 29! - 27! by finding their intersection in a 2D array (like how we have a table for multiplication, where the intersection is the answer) we could solve big factorials. |
That sounds like an application specific thing. Again, I'm not sure what the issue is. There are bignum classes around that can handle integers beyond the range of machine word integers.
Lastly @kbw, why does compile time and run time make difference if they're doing the same task? They're gonna take the same time to process aren't they? If not compile time must be more inefficient because it is finding factorials of non-used factors. I just didn't get why we're using compile time!
For filling the table of course I will have to solve factorials, but then again why the heck would compile time be more useful even in this case? |
If the task is done at compile time, the time is spend during code creation. If the task is done at runtime, it's done every time the program is run. There's a
huge difference.
Even for filling the table I think it's a better idea to rely on online websites that can handle large numbers unlike c++ STL. |
I don't know what you mean by
online websites that can handle large numbers. Website are just published material, whether that be an API, or human consumable content. STL isn't a number type. It's an attempt to provide generic algorithms and containers that are independent of datatype in a minimal way.
Like I said, if you want larger integer types, take look at bignum implementations.