| mm4rs0 (5) | |||
Hey, I have a factorial program, and I need to use Bignum libraries, but I can't figure them out. It would be awesome if somebody could help out. Here's my code:
| |||
|
|
|||
| Zhuge (2871) | |
| I do not see any bignum libraries being used in that code... | |
|
|
|
| mm4rs0 (5) | |
| Exactly. I need to know how to use the libraries. I just put that there in case you were curious. | |
|
|
|
| mm4rs0 (5) | |||
Ok, so I found a library: https://mattmccutchen.net/bigint/
But I get a bunch of "Undefined reference" errors. | |||
|
Last edited on
|
|||
| mm4rs0 (5) | |
| Well it looks like it's a library error, I'll try a different one. | |
|
|
|
| Chervil (806) | |
|
A library error, or an error in using the library? I would expect there to be two parts to using a library: 1. include the appropriate header. The compiler will use this. 2. add the corresponding library file to the project. The linker will use this. I'm guessing that you may have got linker errors because the file was either not added properly to the project, or the linker looked for it but not in the correct path. | |
|
|
|
| Chervil (806) | |
|
I've actually just tried using the above library. The correct procedure would be to first build the library, and then use the pre-built version in actual projects. However, for my quick test, I instead added all the files to my project. That means I have #include "BigIntegerLibrary.hh" in my source code.I included all of these files as part of my project: BigInteger.cc BigIntegerAlgorithms.cc BigIntegerUtils.cc BigUnsigned.cc BigUnsignedInABase.cc So far I'm not very impressed. The library does seem to work, but takes forever to actually output the result. Maybe that's normal for this type of bignum. | |
|
|
|
| mm4rs0 (5) | |
|
Ok, does anyone have suggestions for libraries? | |
|
|
|
| Moschops (5959) | |
| The GNU Bignum library. | |
|
|
|
| Chervil (806) | |||
I may have been a bit harsh in my comments here. It really depends on the type of problems for which the library is used. For example, doing calculations with numbers of say 100 or 1000 digits is one thing. But when doing factorial calculations, the number of digits can rapidly grow very large. As an example, 108654 factorial has half a million digits. Some libraries may calculate this in a moderate amount of time, but struggle with output of the result. The reason for that is the internal operation may be binary, but the output is required in decimal format. Anyway, one of my favourite libraries is Michael C. Ring's MAPM which calculates 108654! in about 9 seconds (on my old laptop). Output of the entire 500002 digit result (to a text file) took 30 milliseconds. Some of the other libraries may be somewhat faster in the calculation, but could take minutes or perhaps hours to produce the output. So - choice of library may depend on the goals. | |||
|
|
|||