[Numpy-svn] r8322 - trunk/numpy/core/src/npymath

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Apr 5 00:03:25 EDT 2010


Author: charris
Date: 2010-04-04 23:03:25 -0500 (Sun, 04 Apr 2010)
New Revision: 8322

Modified:
   trunk/numpy/core/src/npymath/npy_math.c.src
Log:
ENH: Try to make log1p a bit more resistant to compiler shenanigans.
STY: Couple of style fixups.

Modified: trunk/numpy/core/src/npymath/npy_math.c.src
===================================================================
--- trunk/numpy/core/src/npymath/npy_math.c.src	2010-04-05 04:03:22 UTC (rev 8321)
+++ trunk/numpy/core/src/npymath/npy_math.c.src	2010-04-05 04:03:25 UTC (rev 8322)
@@ -65,13 +65,14 @@
 #ifndef HAVE_EXPM1
 double npy_expm1(double x)
 {
-    double u = npy_exp(x);
+    const double u = npy_exp(x);
+
     if (u == 1.0) {
         return x;
-    } else if (u-1.0 == -1.0) {
+    } else if (u - 1.0 == -1.0) {
         return -1;
     } else {
-        return (u-1.0) * x/npy_log(u);
+        return (u - 1.0) * x/npy_log(u);
     }
 }
 #endif
@@ -79,11 +80,13 @@
 #ifndef HAVE_LOG1P
 double npy_log1p(double x)
 {
-    double u = 1. + x;
-    if (u == 1.0) {
+    const double u = 1. + x;
+    const double d = u - 1.;
+
+    if (d == 0) {
         return x;
     } else {
-        return npy_log(u) * x / (u - 1);
+        return npy_log(u) * x / d;
     }
 }
 #endif




More information about the Numpy-svn mailing list