# numeric emulation and __pos__

casevh casevh at gmail.com
Wed Jul 9 05:41:41 CEST 2008

```On Jul 7, 4:12 pm, Ethan Furman <et... at stoneleaf.us> wrote:
> Greetings, List!
>
> I'm working on a numeric data type for measured values that will keep
> track of and limit results to the number of significant digits
> originally defined for the values in question.
>
> I am doing this primarily because I enjoy playing with numbers, and also
> to get some experience with unit testing.
>
> At this point I have the __init__ portion finished, and am starting on
> the various operator functions.
>
> Questions for the group:
>
> 1) Any reason to support the less common operators?
>         i.e. <<, >>, &, ^, |
Assuming you are working with decimal numbers, the &, ^, | may not be
of any use for your application. The shift operators may be useful but
there are two possible ways to define their behavior:

1) Multiplication or division by powers of 2. This mimics the common
use of those operators as used with binary numbers.

2) Multiplication or division by powers of 10.

>
> 2) What, exactly, does .__pos__() do?  An example would help, too.

The unary + operator is frequently added for symmetry with -, however
it is also used to force an existing number to match a new precision
setting. For example, using the decimal module:

>>> from decimal import *
>>> t=Decimal('1.23456')
>>> t
Decimal("1.23456")
>>> getcontext().prec = 5
>>> +t
Decimal("1.2346")

>
> Thanks for the feedback.
> --
> Ethan

casevh

```