Division 1 by a huge integer

I need to divide 1 by the number X of more than 4000 digits that I saved in the string, and obviously this will return a floating point number. I am looking for algorithms to effectively perform this separation, but I could not find anything that convinced me.

As a note, I would like to implement the algorithm myself, without using a third-party library.

Does anyone have an idea?

Thanks!

EDIT : The reason why I do not want to use a third-party library, I want me to perform this operation using openCL, but without losing too high accuracy in this process. Therefore, the use of one of these libraries is actually impossible in this case.

+6
source share
4 answers

You describe a special case of division, known as inverting a number. Here's an article that describes the Picard Iteration Method for inverting a large integer: http://www.dcc.uchile.cl/~cgutierr/ftp/picarte.pdf

+10
source

You should take a look at the GNU multipoint arithmetic library , it has no size limits for the numbers being processed, and obviously there will be insanely well optimized number crunching algorithms.

As for its implementation, if it is not for educational purposes, I would say that do not become a victim of NIH syndrome! And a binary arithmetic web search should provide plenty of documents to start with ...

+2
source

You should use the System.Numerics.BigInteger structure, it allows you to do a lot of calculations, however it is only available in .NET 4.0

+1
source

If your number X is an integer, you may not be able to do what you want. float and double are pretty much broken; you will have to use long double . On some platforms, a long double is simply double .

If you do not want to use a third-party bignum package (why?), You will have to implement the separation algorithm yourself (and this will largely require you to develop a good bignum fragment).

+1
source

Source: https://habr.com/ru/post/893180/


All Articles