[Python-checkins] r50492 - sandbox/trunk/decimal-c/_decimal.c

mateusz.rukowicz python-checkins at python.org
Sun Jul 9 04:58:47 CEST 2006


Author: mateusz.rukowicz
Date: Sun Jul  9 04:58:46 2006
New Revision: 50492

Modified:
   sandbox/trunk/decimal-c/_decimal.c
Log:
Some minor cleanups. Coments udpated a little bit.


Modified: sandbox/trunk/decimal-c/_decimal.c
==============================================================================
--- sandbox/trunk/decimal-c/_decimal.c	(original)
+++ sandbox/trunk/decimal-c/_decimal.c	Sun Jul  9 04:58:46 2006
@@ -11,13 +11,10 @@
    - Rounding constants are integers.
    - There's no handle method on the exceptions.
    - Context methods don't accept keyword arguments (they're all
-     called a and b anyways).
+     called a and b anyways). This probably will be changed.
    - Special values are represented by special sign values, so
      the results of as_tuple() differ.
    - Many internal "underscore" methods are not accessible on the object.
-   - In principle, exponents and the number of digits are unbounded in
-     Python decimals, since they could use long integers. While that's
-     praiseworthy, it's also not very speedy ;)
    - The Python version sometimes gets the context in the middle of
      a method which leads to some calls succeeding even if there is
      no valid context.
@@ -32,14 +29,11 @@
      I guess that this causes slowdown here and there, and the proper way
      to do this is to subclass dict to call back some method on assignment.
      (This is better done in Python code, I guess.)
-   - Some internal methods (names starting with underscores) have been
-     added as a method to the C objects to allow the overlay Python
-     module to use them. They should be removed from that list, along
-     with the wrapper functions parsing the Python arguments, once every-
-     thing is coded in C.
    - Some special (__xxx__) methods in the Python code took additional
      arguments used internally. Since that's not possible, there's a
      _do_decimal_xxx along with a decimal_xxx, see below.
+   - Arithmetic functions (like __add__, __mul__) have only one operand
+     so, we cannot use custom context.
 
    
    This is not yet optimized C code, but mostly translated Python that
@@ -61,6 +55,12 @@
 
    We were undecided whether to offer a public C API (PyDecimal_FromString etc.)
    If you want to do this, look at the datetime module.
+
+   This code still needs some clean-ups and improvements, ie. Context isn't
+   safe for subclassing. Context should become gc object. 'digits' will
+   be removed from decimalobject. Also, I am not really sure, if code is 
+   readable, especially after switching from longs to exp_t - this will
+   need a little work too.
 */
 
 #include "Python.h"
@@ -539,10 +539,10 @@
 }
 #ifdef BIG_EXP
 
-/* TODO this implementation assumes that every limb, which
- * is not used is 0. Since it's not really fast, this will
- * change */
-
+/* TODO I have to *limit* passing arguments by value,
+ * because it really slows down implementation. Most probably
+ * it will also dynamicly switch between C longs/bigint arithmetic
+ * to make things go faster */
 static exp_t 
 exp_from_i(long a) {
     exp_t ret;
@@ -801,7 +801,6 @@
 static exp_t
 exp_mul(exp_t a, exp_t b) {
     exp_t ret;
-/*    memset(ret.limbs, 0, sizeof(long) *EXP_LIMB_COUNT); */
     ret.size = _limb_multiply_core(a.limbs, a.size, b.limbs, b.size, ret.limbs);
     ret.sign = a.sign ^ b.sign;
     if (ret.size == 1 && ret.limbs[0] == 0)
@@ -822,7 +821,6 @@
     for (i=0 ; i<LOG ;i++)
         mult *= 10;
     
-/*    memset(ret.limbs, 0, sizeof(long) * EXP_LIMB_COUNT); */
     *remainder = 0;
     
     for (i = a.size - 1; i>=0; i--) {
@@ -3360,8 +3358,6 @@
     if (ISSPECIAL(self))
         return PyInt_FromLong(0);
 
-    /* XXX: Overflow? */
-/*    return PyInt_FromSsize_t(exp_to_i(ADJUSTED(self))); */
     return exp_to_pyobj(ADJUSTED(self));
 }
 
@@ -4749,7 +4745,7 @@
 }
 DECIMAL_SPECIAL_2FUNC(decimal_floor_div)
 
-
+/* XXX what's the diffirence between div and truediv? =] */
 static decimalobject *
 _do_decimal_true_div(decimalobject *self, decimalobject *other,
                      contextobject *ctx)
@@ -4899,8 +4895,6 @@
     }
 
     firstprec = ctx->prec;
-    /* XXX I am not really sure is this ok, in python implementation it is 
-     * prec + 1 + len(str(n))*/
     ctx->prec += 1;
     {
         long t = n;
@@ -5001,8 +4995,6 @@
     Py_DECREF(mul);
     Py_XDECREF(ret);
     return NULL;
-    /* XXX */
-    Py_RETURN_NONE;
 }
 
 


More information about the Python-checkins mailing list