1#ifndef DFP_UTILS_H
2#define DFP_UTILS_H
3
4#include <stddef.h>      /* size_t */
5#include <stdio.h>       /* printf */
6
7/* convinience macros to print DFP values to avoid linking libdfp to
8   DFP testcases */
9
10#define DFP_VAL_PRINT(op, type)                                         \
11  {                                                                     \
12    size_t n = sizeof(type);                                            \
13    if (n == 4)                                                         \
14      printf("%x", *((unsigned int *) &op));                            \
15    else if (n == 8)                                                    \
16      printf("%lx", *((unsigned long *) &op));                          \
17    else                                                                \
18      printf("%lx%08lx", *((unsigned long *) &op),                      \
19             *(((unsigned long *) &op) + 1));                           \
20  }
21
22#define DFP_BINOP_PRINT(op1, op2, result, type, op, cc)                 \
23  {                                                                     \
24    DFP_VAL_PRINT(op1, type);                                           \
25    printf(" "op" ");                                                   \
26    DFP_VAL_PRINT(op2, type);                                           \
27    printf(" = ");                                                      \
28    DFP_VAL_PRINT(result, type);                                        \
29    printf(" cc = %d\n", cc);                                           \
30  }
31
32#endif /* DFP_UTILS_H */
33