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

mateusz.rukowicz python-checkins at python.org
Sun Jun 11 02:20:35 CEST 2006


Author: mateusz.rukowicz
Date: Sun Jun 11 02:20:34 2006
New Revision: 46843
Modified:
 sandbox/trunk/decimal-c/_decimal.c
Log:
Some bugs repaired. Added conversion of self, that is now 1 + CD("5") works.
Modified: sandbox/trunk/decimal-c/_decimal.c
==============================================================================
--- sandbox/trunk/decimal-c/_decimal.c	(original)
+++ sandbox/trunk/decimal-c/_decimal.c	Sun Jun 11 02:20:34 2006
@@ -1646,7 +1646,7 @@
 if (PyErr_Occurred())
 return NULL;
 
- if ( (res == 0 && (op == Py_EQ || op == Py_LE || op == Py_GT)) ||
+ if ( (res == 0 && (op == Py_EQ || op == Py_LE || op == Py_GT || op == Py_GE)) ||
 (res == -1 && (op == Py_NE || op == Py_LT || op == Py_LE)) ||
 (res == 1 && (op == Py_NE || op == Py_GT || op == Py_GE)))
 Py_RETURN_TRUE;
@@ -2072,12 +2072,15 @@
 return NULL;
 
 for (i = 0; i < self->ob_size; i++) {
- d = PyInt_FromLong(self->digits[i]);
+ d = PyInt_FromLong(_limb_get_digit(self->limbs, self->ob_size, i));	/* SLOW */
 if (!d) return NULL;
 PyTuple_SET_ITEM(digits, i, d);
 }
 
- res = Py_BuildValue("(bOn)", self->sign % 2, digits, self->exp);
+	if(!ISINF(self))
+	 res = Py_BuildValue("(bOn)", self->sign % 2, digits, self->exp);
+	else
+		res = Py_BuildValue("(bOO)", self->sign % 2, digits, PyString_FromString("F"));
 Py_DECREF(digits);
 return res;
 }
@@ -2509,19 +2512,33 @@
 in PyNumberMethods slots. As this can take any objects, but other code
 in this module wants to call some of those methods too, this wrapper
 is a convenience */
+/* Actually, self might be possibly not decimal I assume that self or other 
+ * will be =] */
 #define DECIMAL_SPECIAL_2FUNC(func) \
 static PyObject * \
 func (PyObject *self, PyObject *other) { \
 decimalobject *res; \
+		decimalobject *to_decref;										\
 contextobject *ctx = getcontext(); \
 if (!ctx) return NULL; \
+		if(PyDecimal_Check(self))										\
+		{																\
 other = _convert_to_decimal(self->ob_type, other, ctx, 0); \
- if (other == NULL || other == Py_NotImplemented) return other; \
+ 	 if (other == NULL || other == Py_NotImplemented) return other; \
+		to_decref = other;												\
+		}																\
+		else															\
+		{																\
+		assert(PyDecimal_Check(other));									\
+		self = _convert_to_decimal(other->ob_type, self, ctx, 0);	\
+		to_decref = self;												\
+		if(self == NULL || self == Py_NotImplemented) return self;	\
+		}																\
 res = _do_##func((decimalobject *)self, \
 (decimalobject *)other, ctx); \
- Py_DECREF(other); \
+ Py_DECREF(to_decref); \
 return (PyObject *)res; \
- }
+ }															
 
 /* Same for one-argument methods. */
 #define DECIMAL_SPECIAL_1FUNC(func) \
@@ -2538,6 +2555,8 @@
 _do_decimal_add(decimalobject *self, decimalobject *other,
 contextobject *ctx)
 {
+	assert(PyDecimal_Check(other));
+	assert(PyDecimal_Check(self));
 int shouldround, sign, negativezero = 0;
 long exp, oexp;
 	long prec,cmp;


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /