~inkscape.dev/inkscape-devlibs64/trunk

21 by Eduard Braun
Add Python modules
1
#ifndef __NPY_MATH_C99_H_
2
#define __NPY_MATH_C99_H_
3
4
#ifdef __cplusplus
5
extern "C" {
6
#endif
7
8
#include <math.h>
9
#ifdef __SUNPRO_CC
10
#include <sunmath.h>
11
#endif
12
#ifdef HAVE_NPY_CONFIG_H
13
#include <npy_config.h>
14
#endif
15
#include <numpy/npy_common.h>
16
17
18
/*
19
 * NAN and INFINITY like macros (same behavior as glibc for NAN, same as C99
20
 * for INFINITY)
21
 *
22
 * XXX: I should test whether INFINITY and NAN are available on the platform
23
 */
24
NPY_INLINE static float __npy_inff(void)
25
{
26
    const union { npy_uint32 __i; float __f;} __bint = {0x7f800000UL};
27
    return __bint.__f;
28
}
29
30
NPY_INLINE static float __npy_nanf(void)
31
{
32
    const union { npy_uint32 __i; float __f;} __bint = {0x7fc00000UL};
33
    return __bint.__f;
34
}
35
36
NPY_INLINE static float __npy_pzerof(void)
37
{
38
    const union { npy_uint32 __i; float __f;} __bint = {0x00000000UL};
39
    return __bint.__f;
40
}
41
42
NPY_INLINE static float __npy_nzerof(void)
43
{
44
    const union { npy_uint32 __i; float __f;} __bint = {0x80000000UL};
45
    return __bint.__f;
46
}
47
48
#define NPY_INFINITYF __npy_inff()
49
#define NPY_NANF __npy_nanf()
50
#define NPY_PZEROF __npy_pzerof()
51
#define NPY_NZEROF __npy_nzerof()
52
53
#define NPY_INFINITY ((npy_double)NPY_INFINITYF)
54
#define NPY_NAN ((npy_double)NPY_NANF)
55
#define NPY_PZERO ((npy_double)NPY_PZEROF)
56
#define NPY_NZERO ((npy_double)NPY_NZEROF)
57
58
#define NPY_INFINITYL ((npy_longdouble)NPY_INFINITYF)
59
#define NPY_NANL ((npy_longdouble)NPY_NANF)
60
#define NPY_PZEROL ((npy_longdouble)NPY_PZEROF)
61
#define NPY_NZEROL ((npy_longdouble)NPY_NZEROF)
62
63
/*
64
 * Useful constants
65
 */
66
#define NPY_E         2.718281828459045235360287471352662498  /* e */
67
#define NPY_LOG2E     1.442695040888963407359924681001892137  /* log_2 e */
68
#define NPY_LOG10E    0.434294481903251827651128918916605082  /* log_10 e */
69
#define NPY_LOGE2     0.693147180559945309417232121458176568  /* log_e 2 */
70
#define NPY_LOGE10    2.302585092994045684017991454684364208  /* log_e 10 */
71
#define NPY_PI        3.141592653589793238462643383279502884  /* pi */
72
#define NPY_PI_2      1.570796326794896619231321691639751442  /* pi/2 */
73
#define NPY_PI_4      0.785398163397448309615660845819875721  /* pi/4 */
74
#define NPY_1_PI      0.318309886183790671537767526745028724  /* 1/pi */
75
#define NPY_2_PI      0.636619772367581343075535053490057448  /* 2/pi */
76
#define NPY_EULER     0.577215664901532860606512090082402431  /* Euler constant */
77
#define NPY_SQRT2     1.414213562373095048801688724209698079  /* sqrt(2) */
78
#define NPY_SQRT1_2   0.707106781186547524400844362104849039  /* 1/sqrt(2) */
79
80
#define NPY_Ef        2.718281828459045235360287471352662498F /* e */
81
#define NPY_LOG2Ef    1.442695040888963407359924681001892137F /* log_2 e */
82
#define NPY_LOG10Ef   0.434294481903251827651128918916605082F /* log_10 e */
83
#define NPY_LOGE2f    0.693147180559945309417232121458176568F /* log_e 2 */
84
#define NPY_LOGE10f   2.302585092994045684017991454684364208F /* log_e 10 */
85
#define NPY_PIf       3.141592653589793238462643383279502884F /* pi */
86
#define NPY_PI_2f     1.570796326794896619231321691639751442F /* pi/2 */
87
#define NPY_PI_4f     0.785398163397448309615660845819875721F /* pi/4 */
88
#define NPY_1_PIf     0.318309886183790671537767526745028724F /* 1/pi */
89
#define NPY_2_PIf     0.636619772367581343075535053490057448F /* 2/pi */
34 by Eduard Braun
Update Python to version 2.7.12
90
#define NPY_EULERf    0.577215664901532860606512090082402431F /* Euler constant */
21 by Eduard Braun
Add Python modules
91
#define NPY_SQRT2f    1.414213562373095048801688724209698079F /* sqrt(2) */
92
#define NPY_SQRT1_2f  0.707106781186547524400844362104849039F /* 1/sqrt(2) */
93
94
#define NPY_El        2.718281828459045235360287471352662498L /* e */
95
#define NPY_LOG2El    1.442695040888963407359924681001892137L /* log_2 e */
96
#define NPY_LOG10El   0.434294481903251827651128918916605082L /* log_10 e */
97
#define NPY_LOGE2l    0.693147180559945309417232121458176568L /* log_e 2 */
98
#define NPY_LOGE10l   2.302585092994045684017991454684364208L /* log_e 10 */
99
#define NPY_PIl       3.141592653589793238462643383279502884L /* pi */
100
#define NPY_PI_2l     1.570796326794896619231321691639751442L /* pi/2 */
101
#define NPY_PI_4l     0.785398163397448309615660845819875721L /* pi/4 */
102
#define NPY_1_PIl     0.318309886183790671537767526745028724L /* 1/pi */
103
#define NPY_2_PIl     0.636619772367581343075535053490057448L /* 2/pi */
34 by Eduard Braun
Update Python to version 2.7.12
104
#define NPY_EULERl    0.577215664901532860606512090082402431L /* Euler constant */
21 by Eduard Braun
Add Python modules
105
#define NPY_SQRT2l    1.414213562373095048801688724209698079L /* sqrt(2) */
106
#define NPY_SQRT1_2l  0.707106781186547524400844362104849039L /* 1/sqrt(2) */
107
108
/*
109
 * C99 double math funcs
110
 */
111
double npy_sin(double x);
112
double npy_cos(double x);
113
double npy_tan(double x);
114
double npy_sinh(double x);
115
double npy_cosh(double x);
116
double npy_tanh(double x);
117
118
double npy_asin(double x);
119
double npy_acos(double x);
120
double npy_atan(double x);
121
122
double npy_log(double x);
123
double npy_log10(double x);
124
double npy_exp(double x);
125
double npy_sqrt(double x);
126
double npy_cbrt(double x);
127
128
double npy_fabs(double x);
129
double npy_ceil(double x);
130
double npy_fmod(double x, double y);
131
double npy_floor(double x);
132
133
double npy_expm1(double x);
134
double npy_log1p(double x);
135
double npy_hypot(double x, double y);
136
double npy_acosh(double x);
137
double npy_asinh(double xx);
138
double npy_atanh(double x);
139
double npy_rint(double x);
140
double npy_trunc(double x);
141
double npy_exp2(double x);
142
double npy_log2(double x);
143
144
double npy_atan2(double x, double y);
145
double npy_pow(double x, double y);
146
double npy_modf(double x, double* y);
147
double npy_frexp(double x, int* y);
148
double npy_ldexp(double n, int y);
149
150
double npy_copysign(double x, double y);
151
double npy_nextafter(double x, double y);
152
double npy_spacing(double x);
153
154
/*
155
 * IEEE 754 fpu handling. Those are guaranteed to be macros
156
 */
157
158
/* use builtins to avoid function calls in tight loops
159
 * only available if npy_config.h is available (= numpys own build) */
160
#if HAVE___BUILTIN_ISNAN
161
    #define npy_isnan(x) __builtin_isnan(x)
162
#else
163
    #ifndef NPY_HAVE_DECL_ISNAN
164
        #define npy_isnan(x) ((x) != (x))
165
    #else
166
        #if defined(_MSC_VER) && (_MSC_VER < 1900)
167
            #define npy_isnan(x) _isnan((x))
168
        #else
169
            #define npy_isnan(x) isnan(x)
170
        #endif
171
    #endif
172
#endif
173
174
175
/* only available if npy_config.h is available (= numpys own build) */
176
#if HAVE___BUILTIN_ISFINITE
177
    #define npy_isfinite(x) __builtin_isfinite(x)
178
#else
179
    #ifndef NPY_HAVE_DECL_ISFINITE
180
        #ifdef _MSC_VER
181
            #define npy_isfinite(x) _finite((x))
182
        #else
183
            #define npy_isfinite(x) !npy_isnan((x) + (-x))
184
        #endif
185
    #else
186
        #define npy_isfinite(x) isfinite((x))
187
    #endif
188
#endif
189
190
/* only available if npy_config.h is available (= numpys own build) */
191
#if HAVE___BUILTIN_ISINF
192
    #define npy_isinf(x) __builtin_isinf(x)
193
#else
194
    #ifndef NPY_HAVE_DECL_ISINF
195
        #define npy_isinf(x) (!npy_isfinite(x) && !npy_isnan(x))
196
    #else
197
        #if defined(_MSC_VER) && (_MSC_VER < 1900)
198
            #define npy_isinf(x) (!_finite((x)) && !_isnan((x)))
199
        #else
200
            #define npy_isinf(x) isinf((x))
201
        #endif
202
    #endif
203
#endif
204
205
#ifndef NPY_HAVE_DECL_SIGNBIT
206
    int _npy_signbit_f(float x);
207
    int _npy_signbit_d(double x);
208
    int _npy_signbit_ld(long double x);
209
    #define npy_signbit(x) \
210
        (sizeof (x) == sizeof (long double) ? _npy_signbit_ld (x) \
211
         : sizeof (x) == sizeof (double) ? _npy_signbit_d (x) \
212
         : _npy_signbit_f (x))
213
#else
214
    #define npy_signbit(x) signbit((x))
215
#endif
216
217
/*
218
 * float C99 math functions
219
 */
220
221
float npy_sinf(float x);
222
float npy_cosf(float x);
223
float npy_tanf(float x);
224
float npy_sinhf(float x);
225
float npy_coshf(float x);
226
float npy_tanhf(float x);
227
float npy_fabsf(float x);
228
float npy_floorf(float x);
229
float npy_ceilf(float x);
230
float npy_rintf(float x);
231
float npy_truncf(float x);
232
float npy_sqrtf(float x);
233
float npy_cbrtf(float x);
234
float npy_log10f(float x);
235
float npy_logf(float x);
236
float npy_expf(float x);
237
float npy_expm1f(float x);
238
float npy_asinf(float x);
239
float npy_acosf(float x);
240
float npy_atanf(float x);
241
float npy_asinhf(float x);
242
float npy_acoshf(float x);
243
float npy_atanhf(float x);
244
float npy_log1pf(float x);
245
float npy_exp2f(float x);
246
float npy_log2f(float x);
247
248
float npy_atan2f(float x, float y);
249
float npy_hypotf(float x, float y);
250
float npy_powf(float x, float y);
251
float npy_fmodf(float x, float y);
252
253
float npy_modff(float x, float* y);
254
float npy_frexpf(float x, int* y);
255
float npy_ldexpf(float x, int y);
256
257
float npy_copysignf(float x, float y);
258
float npy_nextafterf(float x, float y);
259
float npy_spacingf(float x);
260
261
/*
262
 * long double C99 math functions
263
 */
264
265
npy_longdouble npy_sinl(npy_longdouble x);
266
npy_longdouble npy_cosl(npy_longdouble x);
267
npy_longdouble npy_tanl(npy_longdouble x);
268
npy_longdouble npy_sinhl(npy_longdouble x);
269
npy_longdouble npy_coshl(npy_longdouble x);
270
npy_longdouble npy_tanhl(npy_longdouble x);
271
npy_longdouble npy_fabsl(npy_longdouble x);
272
npy_longdouble npy_floorl(npy_longdouble x);
273
npy_longdouble npy_ceill(npy_longdouble x);
274
npy_longdouble npy_rintl(npy_longdouble x);
275
npy_longdouble npy_truncl(npy_longdouble x);
276
npy_longdouble npy_sqrtl(npy_longdouble x);
277
npy_longdouble npy_cbrtl(npy_longdouble x);
278
npy_longdouble npy_log10l(npy_longdouble x);
279
npy_longdouble npy_logl(npy_longdouble x);
280
npy_longdouble npy_expl(npy_longdouble x);
281
npy_longdouble npy_expm1l(npy_longdouble x);
282
npy_longdouble npy_asinl(npy_longdouble x);
283
npy_longdouble npy_acosl(npy_longdouble x);
284
npy_longdouble npy_atanl(npy_longdouble x);
285
npy_longdouble npy_asinhl(npy_longdouble x);
286
npy_longdouble npy_acoshl(npy_longdouble x);
287
npy_longdouble npy_atanhl(npy_longdouble x);
288
npy_longdouble npy_log1pl(npy_longdouble x);
289
npy_longdouble npy_exp2l(npy_longdouble x);
290
npy_longdouble npy_log2l(npy_longdouble x);
291
292
npy_longdouble npy_atan2l(npy_longdouble x, npy_longdouble y);
293
npy_longdouble npy_hypotl(npy_longdouble x, npy_longdouble y);
294
npy_longdouble npy_powl(npy_longdouble x, npy_longdouble y);
295
npy_longdouble npy_fmodl(npy_longdouble x, npy_longdouble y);
296
297
npy_longdouble npy_modfl(npy_longdouble x, npy_longdouble* y);
298
npy_longdouble npy_frexpl(npy_longdouble x, int* y);
299
npy_longdouble npy_ldexpl(npy_longdouble x, int y);
300
301
npy_longdouble npy_copysignl(npy_longdouble x, npy_longdouble y);
302
npy_longdouble npy_nextafterl(npy_longdouble x, npy_longdouble y);
303
npy_longdouble npy_spacingl(npy_longdouble x);
304
305
/*
306
 * Non standard functions
307
 */
308
double npy_deg2rad(double x);
309
double npy_rad2deg(double x);
310
double npy_logaddexp(double x, double y);
311
double npy_logaddexp2(double x, double y);
34 by Eduard Braun
Update Python to version 2.7.12
312
double npy_divmod(double x, double y, double *modulus);
21 by Eduard Braun
Add Python modules
313
314
float npy_deg2radf(float x);
315
float npy_rad2degf(float x);
316
float npy_logaddexpf(float x, float y);
317
float npy_logaddexp2f(float x, float y);
34 by Eduard Braun
Update Python to version 2.7.12
318
float npy_divmodf(float x, float y, float *modulus);
21 by Eduard Braun
Add Python modules
319
320
npy_longdouble npy_deg2radl(npy_longdouble x);
321
npy_longdouble npy_rad2degl(npy_longdouble x);
322
npy_longdouble npy_logaddexpl(npy_longdouble x, npy_longdouble y);
323
npy_longdouble npy_logaddexp2l(npy_longdouble x, npy_longdouble y);
34 by Eduard Braun
Update Python to version 2.7.12
324
npy_longdouble npy_divmodl(npy_longdouble x, npy_longdouble y,
325
                           npy_longdouble *modulus);
21 by Eduard Braun
Add Python modules
326
327
#define npy_degrees npy_rad2deg
328
#define npy_degreesf npy_rad2degf
329
#define npy_degreesl npy_rad2degl
330
331
#define npy_radians npy_deg2rad
332
#define npy_radiansf npy_deg2radf
333
#define npy_radiansl npy_deg2radl
334
335
/*
336
 * Complex declarations
337
 */
338
339
/*
340
 * C99 specifies that complex numbers have the same representation as
341
 * an array of two elements, where the first element is the real part
342
 * and the second element is the imaginary part.
343
 */
344
#define __NPY_CPACK_IMP(x, y, type, ctype)   \
345
    union {                                  \
346
        ctype z;                             \
347
        type a[2];                           \
348
    } z1;;                                   \
349
                                             \
350
    z1.a[0] = (x);                           \
351
    z1.a[1] = (y);                           \
352
                                             \
353
    return z1.z;
354
355
static NPY_INLINE npy_cdouble npy_cpack(double x, double y)
356
{
357
    __NPY_CPACK_IMP(x, y, double, npy_cdouble);
358
}
359
360
static NPY_INLINE npy_cfloat npy_cpackf(float x, float y)
361
{
362
    __NPY_CPACK_IMP(x, y, float, npy_cfloat);
363
}
364
365
static NPY_INLINE npy_clongdouble npy_cpackl(npy_longdouble x, npy_longdouble y)
366
{
367
    __NPY_CPACK_IMP(x, y, npy_longdouble, npy_clongdouble);
368
}
369
#undef __NPY_CPACK_IMP
370
371
/*
372
 * Same remark as above, but in the other direction: extract first/second
373
 * member of complex number, assuming a C99-compatible representation
374
 *
375
 * Those are defineds as static inline, and such as a reasonable compiler would
376
 * most likely compile this to one or two instructions (on CISC at least)
377
 */
378
#define __NPY_CEXTRACT_IMP(z, index, type, ctype)   \
379
    union {                                         \
380
        ctype z;                                    \
381
        type a[2];                                  \
382
    } __z_repr;                                     \
383
    __z_repr.z = z;                                 \
384
                                                    \
385
    return __z_repr.a[index];
386
387
static NPY_INLINE double npy_creal(npy_cdouble z)
388
{
389
    __NPY_CEXTRACT_IMP(z, 0, double, npy_cdouble);
390
}
391
392
static NPY_INLINE double npy_cimag(npy_cdouble z)
393
{
394
    __NPY_CEXTRACT_IMP(z, 1, double, npy_cdouble);
395
}
396
397
static NPY_INLINE float npy_crealf(npy_cfloat z)
398
{
399
    __NPY_CEXTRACT_IMP(z, 0, float, npy_cfloat);
400
}
401
402
static NPY_INLINE float npy_cimagf(npy_cfloat z)
403
{
404
    __NPY_CEXTRACT_IMP(z, 1, float, npy_cfloat);
405
}
406
407
static NPY_INLINE npy_longdouble npy_creall(npy_clongdouble z)
408
{
409
    __NPY_CEXTRACT_IMP(z, 0, npy_longdouble, npy_clongdouble);
410
}
411
412
static NPY_INLINE npy_longdouble npy_cimagl(npy_clongdouble z)
413
{
414
    __NPY_CEXTRACT_IMP(z, 1, npy_longdouble, npy_clongdouble);
415
}
416
#undef __NPY_CEXTRACT_IMP
417
418
/*
419
 * Double precision complex functions
420
 */
421
double npy_cabs(npy_cdouble z);
422
double npy_carg(npy_cdouble z);
423
424
npy_cdouble npy_cexp(npy_cdouble z);
425
npy_cdouble npy_clog(npy_cdouble z);
426
npy_cdouble npy_cpow(npy_cdouble x, npy_cdouble y);
427
428
npy_cdouble npy_csqrt(npy_cdouble z);
429
430
npy_cdouble npy_ccos(npy_cdouble z);
431
npy_cdouble npy_csin(npy_cdouble z);
432
npy_cdouble npy_ctan(npy_cdouble z);
433
434
npy_cdouble npy_ccosh(npy_cdouble z);
435
npy_cdouble npy_csinh(npy_cdouble z);
436
npy_cdouble npy_ctanh(npy_cdouble z);
437
438
npy_cdouble npy_cacos(npy_cdouble z);
439
npy_cdouble npy_casin(npy_cdouble z);
440
npy_cdouble npy_catan(npy_cdouble z);
441
442
npy_cdouble npy_cacosh(npy_cdouble z);
443
npy_cdouble npy_casinh(npy_cdouble z);
444
npy_cdouble npy_catanh(npy_cdouble z);
445
446
/*
447
 * Single precision complex functions
448
 */
449
float npy_cabsf(npy_cfloat z);
450
float npy_cargf(npy_cfloat z);
451
452
npy_cfloat npy_cexpf(npy_cfloat z);
453
npy_cfloat npy_clogf(npy_cfloat z);
454
npy_cfloat npy_cpowf(npy_cfloat x, npy_cfloat y);
455
456
npy_cfloat npy_csqrtf(npy_cfloat z);
457
458
npy_cfloat npy_ccosf(npy_cfloat z);
459
npy_cfloat npy_csinf(npy_cfloat z);
460
npy_cfloat npy_ctanf(npy_cfloat z);
461
462
npy_cfloat npy_ccoshf(npy_cfloat z);
463
npy_cfloat npy_csinhf(npy_cfloat z);
464
npy_cfloat npy_ctanhf(npy_cfloat z);
465
466
npy_cfloat npy_cacosf(npy_cfloat z);
467
npy_cfloat npy_casinf(npy_cfloat z);
468
npy_cfloat npy_catanf(npy_cfloat z);
469
470
npy_cfloat npy_cacoshf(npy_cfloat z);
471
npy_cfloat npy_casinhf(npy_cfloat z);
472
npy_cfloat npy_catanhf(npy_cfloat z);
473
474
475
/*
476
 * Extended precision complex functions
477
 */
478
npy_longdouble npy_cabsl(npy_clongdouble z);
479
npy_longdouble npy_cargl(npy_clongdouble z);
480
481
npy_clongdouble npy_cexpl(npy_clongdouble z);
482
npy_clongdouble npy_clogl(npy_clongdouble z);
483
npy_clongdouble npy_cpowl(npy_clongdouble x, npy_clongdouble y);
484
485
npy_clongdouble npy_csqrtl(npy_clongdouble z);
486
487
npy_clongdouble npy_ccosl(npy_clongdouble z);
488
npy_clongdouble npy_csinl(npy_clongdouble z);
489
npy_clongdouble npy_ctanl(npy_clongdouble z);
490
491
npy_clongdouble npy_ccoshl(npy_clongdouble z);
492
npy_clongdouble npy_csinhl(npy_clongdouble z);
493
npy_clongdouble npy_ctanhl(npy_clongdouble z);
494
495
npy_clongdouble npy_cacosl(npy_clongdouble z);
496
npy_clongdouble npy_casinl(npy_clongdouble z);
497
npy_clongdouble npy_catanl(npy_clongdouble z);
498
499
npy_clongdouble npy_cacoshl(npy_clongdouble z);
500
npy_clongdouble npy_casinhl(npy_clongdouble z);
501
npy_clongdouble npy_catanhl(npy_clongdouble z);
502
503
504
/*
505
 * Functions that set the floating point error
506
 * status word.
507
 */
508
509
/*
510
 * platform-dependent code translates floating point
511
 * status to an integer sum of these values
512
 */
513
#define NPY_FPE_DIVIDEBYZERO  1
514
#define NPY_FPE_OVERFLOW      2
515
#define NPY_FPE_UNDERFLOW     4
516
#define NPY_FPE_INVALID       8
517
518
int npy_get_floatstatus(void);
519
int npy_clear_floatstatus(void);
520
void npy_set_floatstatus_divbyzero(void);
521
void npy_set_floatstatus_overflow(void);
522
void npy_set_floatstatus_underflow(void);
523
void npy_set_floatstatus_invalid(void);
524
525
#ifdef __cplusplus
526
}
527
#endif
528
529
#endif