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

mateusz.rukowicz python-checkins at python.org
Sat Jun 10 23:30:16 CEST 2006


Author: mateusz.rukowicz
Date: Sat Jun 10 23:30:15 2006
New Revision: 46836

Modified:
   sandbox/trunk/decimal-c/_decimal.c
Log:
Max now works and passes every test.


Modified: sandbox/trunk/decimal-c/_decimal.c
==============================================================================
--- sandbox/trunk/decimal-c/_decimal.c	(original)
+++ sandbox/trunk/decimal-c/_decimal.c	Sat Jun 10 23:30:15 2006
@@ -1604,7 +1604,9 @@
 _do_decimal_max(decimalobject *self, decimalobject *other,
                 contextobject *ctx)
 {
-    decimalobject *ans, *cmp;
+    decimalobject *ans;
+	int cmp;
+	contextobject *ctx2;
     
     if (ISSPECIAL(self) || ISSPECIAL(other)) {
         decimalobject *nan;
@@ -1623,7 +1625,44 @@
             return nan;
     }
 
-    /* XXX */
+	ans = self;		/* let's assume */
+	if(!ctx)
+	{
+		ctx = getcontext();
+	}
+	
+	/* we have to give getcontext() to _do_decimal_compare */
+	ctx2 = getcontext();
+	if(!ctx2)
+		return NULL;
+	
+	cmp = _do_real_decimal_compare(self, other,ctx2);
+	if(PyErr_Occurred())
+		return NULL;
+
+	if(!cmp)
+	{
+		if(self->sign != other->sign)
+		{
+			if(self->sign)
+				ans = other;
+		}
+		else
+		{
+			if(self->exp < other->exp && !self->sign)
+				ans = other;
+			else if(self->exp > other->exp && self->sign)
+				ans = other;
+		}
+	}
+	else if(cmp == -1)
+		ans = other;
+
+	if(ctx ->rounding_dec == ALWAYS_ROUND)
+		return _decimal_fix(ans, ctx);
+
+	Py_INCREF(ans);
+	return ans;
 }
 DECIMAL_BINARY_FUNC(max)
 


More information about the Python-checkins mailing list