Ok, I cut a branch in svn to work with decimal.py (decimal-branch).

I commited the work I made during the last weeks. Right now, the state
is:

- All the operations that already existed pass ok the new tests (except 
``power``). For this, I fixed some bugs, reordered some code (without changing 
functionality), and made only one important change (see below).

- The ``power`` operation has been redefined to allow raising a number to a 
non-integral power, that's why the old code does not pass the new tests.

- These are the new operations (see the spec for info about them, but basically 
you have the logarithmic ones, and a lot that work with Decimal like a binary 
number): and, class, compare-total, compare-total-magnitude, copy, copy-abs, 
copy-negate, copy-sign, exp, fused-multiply-add, invert, ln, log10, logb, 
max-magnitude, min-magnitude, next-minus, next-plus, next-toward, or, rotate, 
scaleb, shift, to-integral-exact, trim, xor. Note that these names are from the 
spec, not the definitive ones.

- Worked a bit in test_decimal, to make it a bit more debug-friendly: now, you 
can call it with the name of the test(s) you want to execute, and it will only 
execute that(those) test(s), and will *not* execute the doctests (normally, I 
have "print"s in the code, so doctests will always fail). Also, you can call it 
with --debug, and it will show the test number, and context, before executing 
each test.


*Important change:* Added a "P" value to the valid exponents. See this test 
(with a precision of 5 in the context), for example::

  maxx670 max      11 -sNaN12345678901 -> -NaN78901  Invalid_operation
  
This is translated to something like::

  Decimal('11').max(Decimal('-sNaN12345678901'))

Doing ``Decimal('-sNaN12345678901')`` must signal InvalidOperation, because the 
payload has more digits that the context, and we can signal it through 
ConversionSyntax or InvalidOperation itself.

ConversionSyntax must return a quiet NaN. In this case, the max operation will 
return the number, and it's not the desired result in this case.

InvalidOperation must return a quiet NaN also, with the original sign, and an 
optional diagnostic information.

The ``max`` operation, so, will always receive a quiet NaN, but it *must* know 
that it was before signaled. And it must know it from the diagnostic 
information.

So far, for diagnostic information we used the Decimal._int digits, because 
that was all that was needed. I think it's more clear to leave there the 
payload digits, and not make that structure more complex, and create the new 
exponent.

"P" is from "phantom" signal, because for everybody asking self._isnan(), it 
will return 1 (quiet NaN). But if you want to look at it in more detail, you 
will now that in a past life, it was signaled...


Any help is greatly appreciated. 

Thank you very much!

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to