A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2004-April/044295.html below:

[Python-Dev] Decimal data type issues

[Python-Dev] Decimal data type issuesTim Peters tim.one at comcast.net
Thu Apr 15 11:32:15 EDT 2004
[Batista, Facundo]
> I'm lost. Help me with an example (that later I'll shamelessly stole to
> use in a test case):
>
>    d1 = Decimal('123')
>    d2 = Decimal('456')
>
> So, long, they have the same context, right?

Context is associated with operations, not with instances, so d1 and d2
don't "have" any context.  It's unclear to me what use (if any) the
Decimal() constructor makes of context right now.  To the extent that the
Decimal() constructor makes of context, to exactly that same extent the
Decimal constructor is "an operation", so while context may affect
Decimal(), I don't know exactly how it does now.  In any case, context has
no effect on the instances d1 and d2 after they're constructed (although
context both affects and is affected by any operations d1 and d2 may later
take part in).

>    getcontext().prec = 46
>
> The precision should change for both d1 and d2, right?

Sorry, it simply doesn't make sense to talk about context wrt instances,
only wrt operations.  If, e.g., you do an operation now, like

    d4 = d1 + d2

then the result of the operation "d1+d2" has precision 46.

>    d3 = Decimal('789')
>
> d3 also has the precision in 46, right?

That depends on how Decimal() is implemented, and I don't know the answer to
that.



More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4