@@ -16,10 +16,10 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1616
1717#ifndef _MSC_VER
1818#ifndef __STDC__
19- extern double fmod Py_PROTO (( double , double ) );
20- extern double frexp Py_PROTO (( double , int * ) );
21- extern double ldexp Py_PROTO (( double , int ) );
22- extern double modf Py_PROTO (( double , double * ) );
19+ extern double fmod ( double , double );
20+ extern double frexp ( double , int * );
21+ extern double ldexp ( double , int );
22+ extern double modf ( double , double * );
2323#endif /* __STDC__ */
2424#endif /* _MSC_VER */
2525
@@ -51,12 +51,10 @@ math_error()
5151}
5252
5353static PyObject *
54- math_1 (args , func )
55- PyObject * args ;
56- double (* func ) Py_FPROTO ((double ));
54+ math_1 (PyObject * args , double (* func ) (double ), char * argsfmt )
5755{
5856 double x ;
59- if (! PyArg_Parse (args , "d" , & x ))
57+ if (! PyArg_ParseTuple (args , argsfmt , & x ))
6058 return NULL ;
6159 errno = 0 ;
6260 PyFPE_START_PROTECT ("in math_1" , return 0 )
@@ -70,12 +68,10 @@ math_1(args, func)
7068}
7169
7270static PyObject *
73- math_2 (args , func )
74- PyObject * args ;
75- double (* func ) Py_FPROTO ((double , double ));
71+ math_2 (PyObject * args , double (* func ) (double , double ), char * argsfmt )
7672{
7773 double x , y ;
78- if (! PyArg_Parse (args , "(dd)" , & x , & y ))
74+ if (! PyArg_ParseTuple (args , argsfmt , & x , & y ))
7975 return NULL ;
8076 errno = 0 ;
8177 PyFPE_START_PROTECT ("in math_2" , return 0 )
@@ -88,77 +84,75 @@ math_2(args, func)
8884 return PyFloat_FromDouble (x );
8985}
9086
91- #define FUNC1 (stubname , func , docstring_name , docstring ) \
92- static PyObject * stubname(self, args) PyObject *self, *args; { \
93- return math_1(args, func); \
87+ #define FUNC1 (funcname , func , docstring ) \
88+ static PyObject * math_##funcname( PyObject *self, PyObject *args) { \
89+ return math_1(args, func, "d:" #funcname ); \
9490 }\
95- static char docstring_name [] = docstring;
91+ static char math_##funcname##_doc [] = docstring;
9692
97- #define FUNC2 (stubname , func , docstring_name , docstring ) \
98- static PyObject * stubname(self, args) PyObject *self, *args; { \
99- return math_2(args, func); \
93+ #define FUNC2 (funcname , func , docstring ) \
94+ static PyObject * math_##funcname( PyObject *self, PyObject *args) { \
95+ return math_2(args, func, "dd:" #funcname ); \
10096 }\
101- static char docstring_name [] = docstring;
97+ static char math_##funcname##_doc [] = docstring;
10298
103- FUNC1 (math_acos , acos , math_acos_doc ,
99+ FUNC1 (acos , acos ,
104100 "acos(x)\n\nReturn the arc cosine of x." )
105- FUNC1 (math_asin , asin , math_asin_doc ,
101+ FUNC1 (asin , asin ,
106102 "asin(x)\n\nReturn the arc sine of x." )
107- FUNC1 (math_atan , atan , math_atan_doc ,
103+ FUNC1 (atan , atan ,
108104 "atan(x)\n\nReturn the arc tangent of x." )
109- FUNC2 (math_atan2 , atan2 , math_atan2_doc ,
105+ FUNC2 (atan2 , atan2 ,
110106 "atan2(y, x)\n\nReturn atan(y/x)." )
111- FUNC1 (math_ceil , ceil , math_ceil_doc ,
107+ FUNC1 (ceil , ceil ,
112108 "ceil(x)\n\nReturn the ceiling of x as a real." )
113- FUNC1 (math_cos , cos , math_cos_doc ,
109+ FUNC1 (cos , cos ,
114110 "cos(x)\n\nReturn the cosine of x." )
115- FUNC1 (math_cosh , cosh , math_cosh_doc ,
111+ FUNC1 (cosh , cosh ,
116112 "cosh(x)\n\nReturn the hyperbolic cosine of x." )
117- FUNC1 (math_exp , exp , math_exp_doc ,
113+ FUNC1 (exp , exp ,
118114 "exp(x)\n\nReturn e raised to the power of x." )
119- FUNC1 (math_fabs , fabs , math_fabs_doc ,
115+ FUNC1 (fabs , fabs ,
120116 "fabs(x)\n\nReturn the absolute value of the real x." )
121- FUNC1 (math_floor , floor , math_floor_doc ,
117+ FUNC1 (floor , floor ,
122118 "floor(x)\n\nReturn the floor of x as a real." )
123- FUNC2 (math_fmod , fmod , math_fmod_doc ,
119+ FUNC2 (fmod , fmod ,
124120 "fmod(x,y)\n\nReturn x % y." )
125- FUNC2 (math_hypot , hypot , math_hypot_doc ,
121+ FUNC2 (hypot , hypot ,
126122 "hypot(x,y)\n\nReturn the Euclidean distance, sqrt(x*x + y*y)." )
127- FUNC1 (math_log , log , math_log_doc ,
123+ FUNC1 (log , log ,
128124 "log(x)\n\nReturn the natural logarithm of x." )
129- FUNC1 (math_log10 , log10 , math_log10_doc ,
125+ FUNC1 (log10 , log10 ,
130126 "log10(x)\n\nReturn the base-10 logarithm of x." )
131127#ifdef MPW_3_1 /* This hack is needed for MPW 3.1 but not for 3.2 ... */
132- FUNC2 (math_pow , power , math_pow_doc ,
133- "power (x,y)\n\nReturn x**y." )
128+ FUNC2 (pow , power ,
129+ "pow (x,y)\n\nReturn x**y." )
134130#else
135- FUNC2 (math_pow , pow , math_pow_doc ,
131+ FUNC2 (pow , pow ,
136132 "pow(x,y)\n\nReturn x**y." )
137133#endif
138134#ifdef HAVE_RINT
139- FUNC1 (math_rint , rint , math_rint_doc ,
135+ FUNC1 (rint , rint ,
140136 "rint(x)\n\nReturn the integer nearest to x as a real." )
141137#endif
142- FUNC1 (math_sin , sin , math_sin_doc ,
138+ FUNC1 (sin , sin ,
143139 "sin(x)\n\nReturn the sine of x." )
144- FUNC1 (math_sinh , sinh , math_sinh_doc ,
140+ FUNC1 (sinh , sinh ,
145141 "sinh(x)\n\nReturn the hyperbolic sine of x." )
146- FUNC1 (math_sqrt , sqrt , math_sqrt_doc ,
142+ FUNC1 (sqrt , sqrt ,
147143 "sqrt(x)\n\nReturn the square root of x." )
148- FUNC1 (math_tan , tan , math_tan_doc ,
144+ FUNC1 (tan , tan ,
149145 "tan(x)\n\nReturn the tangent of x." )
150- FUNC1 (math_tanh , tanh , math_tanh_doc ,
146+ FUNC1 (tanh , tanh ,
151147 "tanh(x)\n\nReturn the hyperbolic tangent of x." )
152148
153149
154150static PyObject *
155- math_frexp (self , args )
156- PyObject * self ;
157- PyObject * args ;
151+ math_frexp (PyObject * self , PyObject * args )
158152{
159153 double x ;
160154 int i ;
161- if (! PyArg_Parse (args , "d" , & x ))
155+ if (! PyArg_ParseTuple (args , "d:frexp " , & x ))
162156 return NULL ;
163157 errno = 0 ;
164158 x = frexp (x , & i );
@@ -177,13 +171,11 @@ If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.";
177171
178172
179173static PyObject *
180- math_ldexp (self , args )
181- PyObject * self ;
182- PyObject * args ;
174+ math_ldexp (PyObject * self , PyObject * args )
183175{
184176 double x ;
185177 int exp ;
186- if (! PyArg_Parse (args , "(di) " , & x , & exp ))
178+ if (! PyArg_ParseTuple (args , "di:ldexp " , & x , & exp ))
187179 return NULL ;
188180 errno = 0 ;
189181 PyFPE_START_PROTECT ("ldexp" , return 0 )
@@ -203,20 +195,18 @@ Return x * (2**i).";
203195
204196
205197static PyObject *
206- math_modf (self , args )
207- PyObject * self ;
208- PyObject * args ;
198+ math_modf (PyObject * self , PyObject * args )
209199{
210200 double x , y ;
211- if (! PyArg_Parse (args , "d" , & x ))
201+ if (! PyArg_ParseTuple (args , "d:modf " , & x ))
212202 return NULL ;
213203 errno = 0 ;
214204#ifdef MPW /* MPW C modf expects pointer to extended as second argument */
215- {
216- extended e ;
217- x = modf (x , & e );
218- y = e ;
219- }
205+ {
206+ extended e ;
207+ x = modf (x , & e );
208+ y = e ;
209+ }
220210#else
221211 x = modf (x , & y );
222212#endif
@@ -234,32 +224,32 @@ of x. The integer part is returned as a real.";
234224
235225
236226static PyMethodDef math_methods [] = {
237- {"acos" , math_acos , 0 , math_acos_doc },
238- {"asin" , math_asin , 0 , math_asin_doc },
239- {"atan" , math_atan , 0 , math_atan_doc },
240- {"atan2" , math_atan2 , 0 , math_atan2_doc },
241- {"ceil" , math_ceil , 0 , math_ceil_doc },
242- {"cos" , math_cos , 0 , math_cos_doc },
243- {"cosh" , math_cosh , 0 , math_cosh_doc },
244- {"exp" , math_exp , 0 , math_exp_doc },
245- {"fabs" , math_fabs , 0 , math_fabs_doc },
246- {"floor" , math_floor , 0 , math_floor_doc },
247- {"fmod" , math_fmod , 0 , math_fmod_doc },
248- {"frexp" , math_frexp , 0 , math_frexp_doc },
249- {"hypot" , math_hypot , 0 , math_hypot_doc },
250- {"ldexp" , math_ldexp , 0 , math_ldexp_doc },
251- {"log" , math_log , 0 , math_log_doc },
252- {"log10" , math_log10 , 0 , math_log10_doc },
253- {"modf" , math_modf , 0 , math_modf_doc },
254- {"pow" , math_pow , 0 , math_pow_doc },
227+ {"acos" , math_acos , METH_VARARGS , math_acos_doc },
228+ {"asin" , math_asin , METH_VARARGS , math_asin_doc },
229+ {"atan" , math_atan , METH_VARARGS , math_atan_doc },
230+ {"atan2" , math_atan2 , METH_VARARGS , math_atan2_doc },
231+ {"ceil" , math_ceil , METH_VARARGS , math_ceil_doc },
232+ {"cos" , math_cos , METH_VARARGS , math_cos_doc },
233+ {"cosh" , math_cosh , METH_VARARGS , math_cosh_doc },
234+ {"exp" , math_exp , METH_VARARGS , math_exp_doc },
235+ {"fabs" , math_fabs , METH_VARARGS , math_fabs_doc },
236+ {"floor" , math_floor , METH_VARARGS , math_floor_doc },
237+ {"fmod" , math_fmod , METH_VARARGS , math_fmod_doc },
238+ {"frexp" , math_frexp , METH_VARARGS , math_frexp_doc },
239+ {"hypot" , math_hypot , METH_VARARGS , math_hypot_doc },
240+ {"ldexp" , math_ldexp , METH_VARARGS , math_ldexp_doc },
241+ {"log" , math_log , METH_VARARGS , math_log_doc },
242+ {"log10" , math_log10 , METH_VARARGS , math_log10_doc },
243+ {"modf" , math_modf , METH_VARARGS , math_modf_doc },
244+ {"pow" , math_pow , METH_VARARGS , math_pow_doc },
255245#ifdef HAVE_RINT
256- {"rint" , math_rint , 0 , math_rint_doc },
246+ {"rint" , math_rint , METH_VARARGS , math_rint_doc },
257247#endif
258- {"sin" , math_sin , 0 , math_sin_doc },
259- {"sinh" , math_sinh , 0 , math_sinh_doc },
260- {"sqrt" , math_sqrt , 0 , math_sqrt_doc },
261- {"tan" , math_tan , 0 , math_tan_doc },
262- {"tanh" , math_tanh , 0 , math_tanh_doc },
248+ {"sin" , math_sin , METH_VARARGS , math_sin_doc },
249+ {"sinh" , math_sinh , METH_VARARGS , math_sinh_doc },
250+ {"sqrt" , math_sqrt , METH_VARARGS , math_sqrt_doc },
251+ {"tan" , math_tan , METH_VARARGS , math_tan_doc },
252+ {"tanh" , math_tanh , METH_VARARGS , math_tanh_doc },
263253 {NULL , NULL } /* sentinel */
264254};
265255
0 commit comments