math: fix test vectors for logb
[libc-test] / src / math / util.h
1 #include <fenv.h>
2 #include <float.h>
3 #include <math.h>
4
5 #undef RN
6 #undef RZ
7 #undef RD
8 #undef RU
9 #define RN FE_TONEAREST
10 #define RZ FE_TOWARDZERO
11 #define RD FE_DOWNWARD
12 #define RU FE_UPWARD
13
14 #undef INEXACT
15 #undef INVALID
16 #undef DIVBYZERO
17 #undef UNDERFLOW
18 #undef OVERFLOW
19 #define INEXACT FE_INEXACT
20 #define INVALID FE_INVALID
21 #define DIVBYZERO FE_DIVBYZERO
22 #define UNDERFLOW FE_UNDERFLOW
23 #define OVERFLOW FE_OVERFLOW
24
25 #undef inf
26 #undef nan
27 #define inf INFINITY
28 #define nan NAN
29
30 #define T(...) {__FILE__, __LINE__, __VA_ARGS__},
31
32 #define POS char *file; int line;
33 struct d_d {POS int r; double x; double y; float dy; int e; };
34 struct f_f {POS int r; float x; float y; float dy; int e; };
35 struct l_l {POS int r; long double x; long double y; float dy; int e; };
36 struct ff_f {POS int r; float x; float x2; float y; float dy; int e; };
37 struct dd_d {POS int r; double x; double x2; double y; float dy; int e; };
38 struct ll_l {POS int r; long double x; long double x2; long double y; float dy; int e; };
39
40 char *estr(int);
41 char *rstr(int);
42 int rconv(int *, char *);
43 int econv(int *, char *);
44
45 int eulp(double);
46 int eulpf(float);
47 int eulpl(long double);
48
49 float ulperr(double got, double want, float dwant);
50 float ulperrf(float got, float want, float dwant);
51 float ulperrl(long double got, long double want, float dwant);
52
53 void setupfenv(int);
54 int getexcept(void);
55
56 static int checkexcept(int got, int want, int r)
57 {
58         if (r == RN)
59                 return got == want || got == (want|INEXACT);
60         return 1; //(got|INEXACT|UNDERFLOW) == (want|INEXACT|UNDERFLOW);
61 }
62
63 static int checkulp(float d, int r)
64 {
65         if (r == RN)
66                 return fabsf(d) <= 1.0;
67         return 1; //fabsf(d) <= 2.0;
68 }
69