On Thu, Jul 1, 2010 at 16:18, Steven D'Aprano <st...@pearwood.info> wrote: > On Fri, 2 Jul 2010 05:18:00 am Eike Welk wrote: > >> As you are using long integers (and you were previously writing about >> prime numbers) the precision of floating point numbers might not be >> enough for your purposes. > > It certainly won't be once you get to large enough primes! > >> Therefore you should probably use the integer division operator: "//" > > And the reminder (or modulo) operator %, together with the combination > function divmod(a, b) which returns (a//b, a%b). The advantage of > divmod is that it is faster than calling a//b followed by a%b.
Thanks to you and Eike, Steven, I was able to write this little function that does the job for me, and more: >>> def divide_large_ints(n, div): x = divmod(n, div) return str(x[0]) + str(x[1]/div).lstrip('0') >>> n = 2000000000000000000000000000000033 >>> div = 2 >>> divide_large_ints(n, div) '1000000000000000000000000000000016.5' >>> Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor