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

mateusz.rukowicz python-checkins at python.org
Mon Oct 15 05:04:47 CEST 2007


Author: mateusz.rukowicz
Date: Mon Oct 15 05:04:46 2007
New Revision: 58467

Modified:
   sandbox/trunk/decimal-c/_decimal.c
Log:
Fixed issues with natural logarithm (However, this function is still TODO, since it's really slugish).


Modified: sandbox/trunk/decimal-c/_decimal.c
==============================================================================
--- sandbox/trunk/decimal-c/_decimal.c	(original)
+++ sandbox/trunk/decimal-c/_decimal.c	Mon Oct 15 05:04:46 2007
@@ -2178,7 +2178,7 @@
     return ans;
 }
 
-//this one cuts off diagnostic information
+/* this one cuts off diagnostic information */
 
 static PyObject *
 decimal_fix(decimalobject *self, PyObject *args, PyObject *kwds)
@@ -4720,6 +4720,10 @@
     5341,  4889,  4437, 39930, 35534, 31186, 26886, 22630, 18418, 14254,
     10130,  6046, 20055};
 
+/* this function passes all tests, but I am not sure if it's always gives answer with
+ * error < 0.5 ulp. I am not sure if there exists such solution (it's ok if we just truncate
+ * digits, but problem arises when using rounding which checks if last digit is 5
+ * and result ens with 50000...00001) */
 static decimalobject *
 _do_decimal__ln(decimalobject *self, contextobject *ctx) {
     
@@ -4812,7 +4816,11 @@
     b->sign = 1;
    
     rounding = ctx1->rounding;
-    ctx1->rounding = ROUND_HALF_EVEN;
+    /* we'll calculate lower bound, There might be problem with 
+     * result which ends wit 50...01 (I dont really think there is rational a,
+     * that ln(a) ends with 500000.... - and we actually operate on rational subset
+     * of R) */
+    ctx1->rounding = ROUND_DOWN;
     tmp = _do_decimal_add(ans, b, ctx1);    
     if (!tmp)
         goto err;
@@ -4896,8 +4904,8 @@
 
     rounding = ctx->rounding;
     ctx->rounding = ROUND_HALF_EVEN;
-    /* we add extra 1 at the end to make proper rounding */
-    if (decimal_nonzero(ans) && !ISSPECIAL(ans)) {
+    /* we add extra 1 at the end to make proper rounding only if last digit is not 0 (to avoid 0.9999999...) */
+    if (decimal_nonzero(ans) && !ISSPECIAL(ans) && (ans->limbs[0] % 10) != 9) {
         int i;
 
         


More information about the Python-checkins mailing list