Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50804 > unrolled thread

Re: Storing a very large number

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2013-07-17 14:10 -0600
Last post2013-07-17 14:10 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Storing a very large number Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-17 14:10 -0600

#50804 — Re: Storing a very large number

FromIan Kelly <ian.g.kelly@gmail.com>
Date2013-07-17 14:10 -0600
SubjectRe: Storing a very large number
Message-ID<mailman.4813.1374091886.3114.python-list@python.org>
On Wed, Jul 17, 2013 at 1:21 PM, Hasit Mistry <hasitnm@lavabit.com> wrote:
> I came across a problem that requires me to store a very large number (say
>>10^100). How do I do it efficiently?

Both the int and Decimal types support arbitrary precision.  Floats do not.

> And also, how do I select a particular number (say 209th) from that very
> large number?

You mean a particular digit?  The most obvious way is to format it as
a string and use indexing.

>>> x = 2 ** 1000
>>> str(x)[208]
'6'

Or using arithmetic:

>>> (x // 10 ** 208) % 10
5

Note that the first method counts digits from the left and will be off
if the value is negative, while the second method counts digits from
the right.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web