@@ -107,9 +107,28 @@ FUNC1(atan, atan,
107
107
FUNC2 (atan2 , atan2 ,
108
108
"atan2(y, x)\n\nReturn the arc tangent (measured in radians) of y/x.\n"
109
109
"Unlike atan(y/x), the signs of both x and y are considered." )
110
- FUNC1 (ceil , ceil ,
111
- "ceil(x)\n\nReturn the ceiling of x as a float.\n"
112
- "This is the smallest integral value >= x." )
110
+
111
+ static PyObject * math_ceil (PyObject * self , PyObject * number ) {
112
+ static PyObject * ceil_str = NULL ;
113
+ PyObject * method ;
114
+
115
+ if (ceil_str == NULL ) {
116
+ ceil_str = PyUnicode_FromString ("__ceil__" );
117
+ if (ceil_str == NULL )
118
+ return NULL ;
119
+ }
120
+
121
+ method = _PyType_Lookup (Py_Type (number ), ceil_str );
122
+ if (method == NULL )
123
+ return math_1 (number , ceil );
124
+ else
125
+ return PyObject_CallFunction (method , "O" , number );
126
+ }
127
+
128
+ PyDoc_STRVAR (math_ceil_doc ,
129
+ "ceil(x)\n\nReturn the ceiling of x as a float.\n"
130
+ "This is the smallest integral value >= x." );
131
+
113
132
FUNC1 (cos , cos ,
114
133
"cos(x)\n\nReturn the cosine of x (measured in radians)." )
115
134
FUNC1 (cosh , cosh ,
@@ -118,9 +137,28 @@ FUNC1(exp, exp,
118
137
"exp(x)\n\nReturn e raised to the power of x." )
119
138
FUNC1 (fabs , fabs ,
120
139
"fabs(x)\n\nReturn the absolute value of the float x." )
121
- FUNC1 (floor , floor ,
122
- "floor(x)\n\nReturn the floor of x as a float.\n"
123
- "This is the largest integral value <= x." )
140
+
141
+ static PyObject * math_floor (PyObject * self , PyObject * number ) {
142
+ static PyObject * floor_str = NULL ;
143
+ PyObject * method ;
144
+
145
+ if (floor_str == NULL ) {
146
+ floor_str = PyUnicode_FromString ("__floor__" );
147
+ if (floor_str == NULL )
148
+ return NULL ;
149
+ }
150
+
151
+ method = _PyType_Lookup (Py_Type (number ), floor_str );
152
+ if (method == NULL )
153
+ return math_1 (number , floor );
154
+ else
155
+ return PyObject_CallFunction (method , "O" , number );
156
+ }
157
+
158
+ PyDoc_STRVAR (math_floor_doc ,
159
+ "floor(x)\n\nReturn the floor of x as a float.\n"
160
+ "This is the largest integral value <= x." );
161
+
124
162
FUNC2 (fmod , fmod ,
125
163
"fmod(x,y)\n\nReturn fmod(x, y), according to platform C."
126
164
" x % y may differ." )
0 commit comments