ulps: Fix long lines
[mathlib.git] / ulps / ulp.h
CommitLineData
a95d68a2
SK
1#ifndef __ULPH_H__
2#define __ULPH_H__
3
a9068f41 4#include <assert.h>
5
a95d68a2
SK
6struct ulp {
7 double ulp_max;
8 double ulp_min;
9 double ulp_avg;
10 size_t ulp_skipped;
8727eb1a 11
12 long double ulp_maxl;
13 long double ulp_minl;
14 long double ulp_avgl;
15 size_t ulp_skippedl;
a95d68a2
SK
16};
17
5226af1e
SK
18struct ulp_complex {
19 struct ulp ulp_real;
20 struct ulp ulp_imag;
4e3bb96b 21 struct ulp ulp_total;
5226af1e
SK
22};
23
5226af1e
SK
24/*******************************************************************************
25 * Real arithmetic
26 ******************************************************************************/
94545ea5 27#define ULP_INIT(u) \
28 assert(u); \
f46d092c 29 (u)->ulp_max = -DBL_MAX; \
30 (u)->ulp_min = DBL_MAX; \
31 (u)->ulp_avg = 0.0; \
32 (u)->ulp_skipped = 0; \
33 (u)->ulp_maxl = -LDBL_MAX; \
34 (u)->ulp_minl = LDBL_MAX; \
35 (u)->ulp_avgl = 0.0; \
36 (u)->ulp_skippedl = 0;
94545ea5 37
38#define ULP_UPDATE(u, n) \
a9068f41 39assert(u); \
40do { \
f46d092c 41 if ((n) > (u)->ulp_max) \
42 (u)->ulp_max = n; \
43 if ((n) < (u)->ulp_min) \
44 (u)->ulp_min = n; \
f91bd554 45 (u)->ulp_avg += n; \
a9068f41 46} while(0)
47
94545ea5 48#define ULP_UPDATEL(u, nl) \
a9068f41 49assert(u); \
50do { \
f46d092c 51 if ((nl) > (u)->ulp_maxl) \
52 (u)->ulp_maxl = nl; \
53 if ((nl) < (u)->ulp_minl) \
54 (u)->ulp_minl = nl; \
f91bd554 55 (u)->ulp_avgl += nl; \
a9068f41 56} while(0)
57
5226af1e
SK
58
59/*******************************************************************************
60 * Complex arithmetic
61 ******************************************************************************/
f91bd554
SK
62#define ULP_COMPLEX_INIT(uc) \
63 ULP_INIT(&uc->ulp_real); \
4e3bb96b
SK
64 ULP_INIT(&uc->ulp_imag); \
65 ULP_INIT(&uc->ulp_total);
f91bd554
SK
66
67#define ULP_COMPLEX_UPDATE(uc, n) \
68assert(uc); \
f46d092c 69ULP_UPDATE(&uc->ulp_real, creal(n)); \
70ULP_UPDATE(&uc->ulp_imag, cimag(n)); \
71ULP_UPDATE(&uc->ulp_total, fabs(creal(n)) + fabs(cimag(n)));
5226af1e 72
47a35535 73#define ULP_COMPLEX_UPDATEL(uc, n) \
f46d092c 74assert(uc); \
75ULP_UPDATEL(&uc->ulp_real, creall(n)); \
76ULP_UPDATEL(&uc->ulp_imag, cimagl(n)); \
77ULP_UPDATEL(&uc->ulp_total, fabsl(creall(n)) + fabsl(cimagl(n)));
47a35535 78
d1e1ecce
SK
79double calculp_double(double computed, double exact);
80long double calculp_long_double(long double computedl, long double exactl);
81
4565678c 82void getfunctionulp_real(const struct fentry *f, struct ulp *u);
ca3e8900 83void getfunctionulp_complex(const struct fentry *f, struct ulp_complex *u);
a95d68a2 84
d1e1ecce
SK
85void printulps_double(struct ulp u);
86void printulps_long_double(struct ulp u);
f91bd554
SK
87void printulps_double_complex(struct ulp_complex u);
88void printulps_long_double_complex(struct ulp_complex u);
3ec3219c 89
80e939cb 90#define NITERATIONS (1 * 1000)
3ec3219c 91
a95d68a2 92#endif /* ! __ULP_H__ */