Message259317
Inspired by the recently new discovered 49th Mersenne prime number I wrote a module to do high speed long/int to decimal conversion. I can now output the new Mersenne number in 18.5 minutes (instead of several hours) on my machine.
For numbers longer than about 100000 bits, this routine it is faster than str(number) thanks to the Karatsuba multiplication in CPython.
The module supports all number bases 2 through 36, and is written in pure python (both 2 and 3).
There is a simple way to save more time by reusing the conversion object (saving about half the time for later calls).
My suggestion is to incorporate this into some library, since Python still lacks a routine to convert to any number base. Ideally, it could be incorporated in the builtin str function, but this would need more work.
When converting to C, it is recommended to optimize bases 4 and 32 the same way as oct, hex and bin do (which isn't easily accessible from Python).
Hope you like it. At least, it was a lot of fun to write...
Hope you like it. |
|
Date |
User |
Action |
Args |
2016-02-01 10:28:35 | jneb | set | recipients:
+ jneb |
2016-02-01 10:28:33 | jneb | set | messageid: <1454322513.41.0.794136944555.issue26256@psf.upfronthosting.co.za> |
2016-02-01 10:28:33 | jneb | link | issue26256 messages |
2016-02-01 10:28:32 | jneb | create | |
|