On 01/07/2013 07:44 PM, Nac Temha wrote:
> Hello,
> How to *quickly* calculate large numbers. For example
>>>> (10**25) * (2**50)
> 11258999068426240000000000000000000000000L
>
>
Since all of the terms are const, you could just use
print "11258999068426240000000000000000000000000L"
Or if you have some constraints on those numbers, you could preprocess the
calculation with meatware.
For example, if you wnated (10**var1) * (var2**var3), where var1, var2 and
var3 are all ints, then you could save some time by doing:
print str(var2**var3)+"0"*var1
Or you could write C code to do multiprecision arithmetic. Or ...
What are your constraints? If you have to calculate an arbitrary expression of
ints and longs, you'll spend a lot more time typing it in than the computer
will calculating it.
BTW, if you want a non-trivial answer, you should specify what Python version
you're targeting. I arbitrarily chose 2.7 for my response.m
--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list