@@ -94,10 +94,11 @@ static const npy_uint64 MAGIC64[] = {0x5555555555555555ull, 0x3333333333333333ul
94
94
* classification instead of calling npy_isinf/npy_isnan: we should have some
95
95
* macros for this, though, instead of doing it manually
96
96
*/
97
- #ifndef HAVE_LOG2
98
97
NPY_INPLACE double npy_log2 (double x )
99
98
{
100
- #ifdef HAVE_FREXP
99
+ #ifdef HAVE_LOG2
100
+ return log2 (x );
101
+ #elif defined(HAVE_FREXP )
101
102
if (!npy_isfinite (x ) || x <= 0. ) {
102
103
/* special value result */
103
104
return npy_log (x );
@@ -127,7 +128,38 @@ NPY_INPLACE double npy_log2(double x)
127
128
return NPY_LOG2E * npy_log (x );
128
129
#endif
129
130
}
131
+
132
+ NPY_INPLACE double npy_hypot (double x , double y )
133
+ {
134
+ #ifdef HAVE_HYPOT
135
+ return hypot (x , y );
136
+ #else
137
+ double yx ;
138
+
139
+ if (npy_isinf (x ) || npy_isinf (y )) {
140
+ return NPY_INFINITY ;
141
+ }
142
+
143
+ if (npy_isnan (x ) || npy_isnan (y )) {
144
+ return NPY_NAN ;
145
+ }
146
+
147
+ x = npy_fabs (x );
148
+ y = npy_fabs (y );
149
+ if (x < y ) {
150
+ double temp = x ;
151
+ x = y ;
152
+ y = temp ;
153
+ }
154
+ if (x == 0. ) {
155
+ return 0. ;
156
+ }
157
+ else {
158
+ yx = y /x ;
159
+ return x * npy_sqrt (1. + yx * yx );
160
+ }
130
161
#endif
162
+ }
131
163
132
164
/*
133
165
*
@@ -194,12 +226,73 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
194
226
195
227
/**end repeat1**/
196
228
229
+ #undef WORKAROUND_APPLE_TRIG_BUG
230
+
231
+ /* C99 mandatory */
232
+
233
+ /**begin repeat1
234
+ * #kind = atan2,fmod,copysign#
235
+ * #KIND = ATAN2,FMOD,COPYSIGN#
236
+ */
237
+ NPY_INPLACE @type @ npy_ @kind @@c @(@type @ x , @type @ y )
238
+ {
239
+ return NPY__FP_SFX (@kind @)(x , y );
240
+ }
241
+ /**end repeat1**/
242
+
243
+
244
+ NPY_INPLACE @type @ npy_modf @c @(@type @ x , @type @ * iptr )
245
+ {
246
+ return NPY__FP_SFX (modf )(x , iptr );
247
+ }
248
+
249
+ NPY_INPLACE @type @ npy_ldexp @c @(@type @ x , int exp )
250
+ {
251
+ return NPY__FP_SFX (ldexp )(x , exp );
252
+ }
253
+
254
+ NPY_INPLACE @type @ npy_frexp @c @(@type @ x , int * exp )
255
+ {
256
+ return NPY__FP_SFX (frexp )(x , exp );
257
+ }
258
+
259
+ NPY_INPLACE @type @ npy_cbrt @c @(@type @ x )
260
+ {
261
+ return NPY__FP_SFX (cbrt )(x );
262
+ }
263
+
264
+ /**end repeat**/
265
+
197
266
/* Optional C99 functions */
198
267
268
+ /**begin repeat
269
+ * #type = npy_longdouble, npy_float#
270
+ * #TYPE = LONGDOUBLE, FLOAT#
271
+ * #c = l,f#
272
+ * #C = L,F#
273
+ */
274
+ #undef NPY__FP_SFX
275
+ #if NPY_SIZEOF_ @TYPE @ == NPY_SIZEOF_DOUBLE
276
+ #define NPY__FP_SFX (X ) X
277
+ #else
278
+ #define NPY__FP_SFX (X ) NPY_CAT(X, @c@)
279
+ #endif
280
+
199
281
/**begin repeat1
200
282
* #kind = log2#
201
283
* #KIND = LOG2#
202
284
*/
285
+
286
+ #ifdef @kind @@c @
287
+ #undef @kind@@c@
288
+ #endif
289
+ #ifndef HAVE_ @KIND @@C @
290
+ NPY_INPLACE @type @ npy_ @kind @@c @(@type @ x )
291
+ {
292
+ return (@type @) npy_ @kind @((double )x );
293
+ }
294
+ #endif
295
+
203
296
#ifdef HAVE_ @KIND @@C @
204
297
NPY_INPLACE @type @ npy_ @kind @@c @(@type @ x )
205
298
{
@@ -209,11 +302,10 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
209
302
210
303
/**end repeat1**/
211
304
212
- #undef WORKAROUND_APPLE_TRIG_BUG
213
305
214
306
/**begin repeat1
215
- * #kind = pow#
216
- * #KIND = POW#
307
+ * #kind = hypot, pow#
308
+ * #KIND = HYPOT, POW#
217
309
*/
218
310
#ifdef @kind @@c @
219
311
#undef @kind@@c@
@@ -232,42 +324,10 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
232
324
}
233
325
#endif
234
326
/**end repeat1**/
327
+ /**end repeat**/
235
328
236
329
237
- /* C99 mandatory */
238
-
239
- /**begin repeat1
240
- * #kind = atan2,hypot,fmod,copysign#
241
- * #KIND = ATAN2,HYPOT,FMOD,COPYSIGN#
242
- */
243
- NPY_INPLACE @type @ npy_ @kind @@c @(@type @ x , @type @ y )
244
- {
245
- return NPY__FP_SFX (@kind @)(x , y );
246
- }
247
- /**end repeat1**/
248
-
249
-
250
- NPY_INPLACE @type @ npy_modf @c @(@type @ x , @type @ * iptr )
251
- {
252
- return NPY__FP_SFX (modf )(x , iptr );
253
- }
254
-
255
- NPY_INPLACE @type @ npy_ldexp @c @(@type @ x , int exp )
256
- {
257
- return NPY__FP_SFX (ldexp )(x , exp );
258
- }
259
-
260
- NPY_INPLACE @type @ npy_frexp @c @(@type @ x , int * exp )
261
- {
262
- return NPY__FP_SFX (frexp )(x , exp );
263
- }
264
-
265
- NPY_INPLACE @type @ npy_cbrt @c @(@type @ x )
266
- {
267
- return NPY__FP_SFX (cbrt )(x );
268
- }
269
330
#undef NPY__FP_SFX
270
- /**end repeat**/
271
331
272
332
273
333
/*
@@ -603,3 +663,10 @@ npy_popcount@c@(npy_@type@ a)
603
663
return npy_popcountu @c @(a < 0 ? - a : a );
604
664
}
605
665
/**end repeat**/
666
+
667
+ /* XXX: will moving this to a define break anything? */
668
+
669
+ NPY_INPLACE double npy_pow (double x , double y )
670
+ {
671
+ return pow (x , y );
672
+ }
0 commit comments