diff Modules/mathmodule.c @ 57756:b206ad8cf5bf legacy-trunk

Issue #3366: Add expm1 function to math module. Thanks Eric Smith for testing on Windows.
author Mark Dickinson <dickinsm@gmail.com>
date Wed, 16 Dec 2009 20:13:40 +0000
parents cb22eaee86c9
children d350afc337dc
line wrap: on
line diff
--- a/Modules/mathmodule.c	Wed Dec 16 11:49:46 2009 +0000
+++ b/Modules/mathmodule.c	Wed Dec 16 20:13:40 2009 +0000
@@ -53,6 +53,7 @@
  */
 
 #include "Python.h"
+#include "_math.h"
 #include "longintrepr.h" /* just for SHIFT */
 
 #ifdef _OSF_SOURCE
@@ -686,6 +687,10 @@
       "cosh(x)\n\nReturn the hyperbolic cosine of x.")
 FUNC1(exp, exp, 1,
       "exp(x)\n\nReturn e raised to the power of x.")
+FUNC1(expm1, m_expm1, 1,
+      "expm1(x)\n\nReturn exp(x)-1.\n"
+      "This function avoids the loss of precision involved in the direct "
+      "evaluation of exp(x)-1 for small x.")
 FUNC1(fabs, fabs, 0,
       "fabs(x)\n\nReturn the absolute value of the float x.")
 FUNC1(floor, floor, 0,
@@ -1420,6 +1425,7 @@
 	{"cosh",	math_cosh,	METH_O,		math_cosh_doc},
 	{"degrees",	math_degrees,	METH_O,		math_degrees_doc},
 	{"exp",		math_exp,	METH_O,		math_exp_doc},
+	{"expm1",	math_expm1,	METH_O,		math_expm1_doc},
 	{"fabs",	math_fabs,	METH_O,		math_fabs_doc},
 	{"factorial",	math_factorial,	METH_O,		math_factorial_doc},
 	{"floor",	math_floor,	METH_O,		math_floor_doc},