1
/* Processed by ecpg (regression mode) */
2
/* These include files are added by the preprocessor */
6
/* Needed for informix compatibility */
7
#include <ecpg_informix.h>
8
/* End of automatic include section */
9
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
11
#line 1 "dec_test.pgc"
14
#include <pgtypes_numeric.h>
15
#include <pgtypes_error.h>
20
#line 1 "regression.h"
27
#line 8 "dec_test.pgc"
33
NOTE: This file has a different expect file for regression tests on MinGW32
43
decimal point: , and/or . ?
44
ECPG_INFORMIX_BAD_EXPONENT ?
47
char* decs[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4",
48
"2E-394", ".1E-2", "+.0", "-592.49E-07", "+32.84e-4",
49
".500001", "-.5000001",
50
"1234567890123456789012345678.91", /* 30 digits should fit
52
"1234567890123456789012345678.921", /* 31 digits should NOT
69
int i, j, k, q, r, count = 0;
71
decimal **decarr = (decimal **) calloc(1, sizeof(decimal));
75
for (i = 0; decs[i]; i++)
77
dec = PGTYPESdecimal_new();
78
r = deccvasc(decs[i], strlen(decs[i]), dec);
82
printf("dec[%d,0]: r: %d\n", i, r);
83
PGTYPESdecimal_free(dec);
86
decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
87
decarr[count++] = dec;
89
r = dectoasc(dec, buf, BUFSIZE-1, -1);
90
if (r < 0) check_errno();
91
printf("dec[%d,1]: r: %d, %s\n", i, r, buf);
93
r = dectoasc(dec, buf, BUFSIZE-1, 0);
94
if (r < 0) check_errno();
95
printf("dec[%d,2]: r: %d, %s\n", i, r, buf);
96
r = dectoasc(dec, buf, BUFSIZE-1, 1);
97
if (r < 0) check_errno();
98
printf("dec[%d,3]: r: %d, %s\n", i, r, buf);
99
r = dectoasc(dec, buf, BUFSIZE-1, 2);
100
if (r < 0) check_errno();
101
printf("dec[%d,4]: r: %d, %s\n", i, r, buf);
103
din = PGTYPESdecimal_new();
104
r = dectoasc(din, buf, BUFSIZE-1, 2);
105
if (r < 0) check_errno();
106
printf("dec[%d,5]: r: %d, %s\n", i, r, buf);
108
r = dectolong(dec, &l);
109
if (r) check_errno();
110
printf("dec[%d,6]: %ld (r: %d)\n", i, r?0L:l, r);
113
r = deccvlong(l, din);
114
if (r) check_errno();
115
dectoasc(din, buf, BUFSIZE-1, 2);
116
q = deccmp(dec, din);
117
printf("dec[%d,7]: %s (r: %d - cmp: %d)\n", i, buf, r, q);
120
r = dectoint(dec, &k);
121
if (r) check_errno();
122
printf("dec[%d,8]: %d (r: %d)\n", i, r?0:k, r);
125
r = deccvint(k, din);
126
if (r) check_errno();
127
dectoasc(din, buf, BUFSIZE-1, 2);
128
q = deccmp(dec, din);
129
printf("dec[%d,9]: %s (r: %d - cmp: %d)\n", i, buf, r, q);
134
/* underflow does not work reliable on several archs, so not testing it here */
135
/* this is a libc problem since we only call strtod() */
136
r = dectodbl(dec, &dbl);
137
if (r) check_errno();
138
printf("dec[%d,10]: %g (r: %d)\n", i, r?0.0:dbl, r);
141
PGTYPESdecimal_free(din);
145
/* add a NULL value */
146
dec = PGTYPESdecimal_new();
147
decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
148
decarr[count++] = dec;
150
rsetnull(CDECIMALTYPE, (char *) decarr[count-1]);
151
printf("dec[%d]: %sNULL\n", count-1,
152
risnull(CDECIMALTYPE, (char *) decarr[count-1]) ? "" : "NOT ");
153
printf("dec[0]: %sNULL\n",
154
risnull(CDECIMALTYPE, (char *) decarr[0]) ? "" : "NOT ");
156
r = dectoasc(decarr[3], buf, -1, -1);
157
check_errno(); printf("dectoasc with len == -1: r: %d\n", r);
158
r = dectoasc(decarr[3], buf, 0, -1);
159
check_errno(); printf("dectoasc with len == 0: r: %d\n", r);
161
for (i = 0; i < count; i++)
163
for (j = 0; j < count; j++)
167
c = deccmp(decarr[i], decarr[j]);
168
printf("dec[c,%d,%d]: %d\n", i, j, c);
170
r = decadd(decarr[i], decarr[j], &a);
174
printf("r: %d\n", r);
178
dectoasc(&a, buf, BUFSIZE-1, -1);
179
printf("dec[a,%d,%d]: %s\n", i, j, buf);
182
r = decsub(decarr[i], decarr[j], &s);
186
printf("r: %d\n", r);
190
dectoasc(&s, buf, BUFSIZE-1, -1);
191
printf("dec[s,%d,%d]: %s\n", i, j, buf);
194
r = decmul(decarr[i], decarr[j], &m);
198
printf("r: %d\n", r);
202
dectoasc(&m, buf, BUFSIZE-1, -1);
203
printf("dec[m,%d,%d]: %s\n", i, j, buf);
206
r = decdiv(decarr[i], decarr[j], &d);
210
printf("r: %d\n", r);
214
dectoasc(&d, buf, BUFSIZE-1, -1);
215
printf("dec[d,%d,%d]: %s\n", i, j, buf);
220
for (i = 0; i < count; i++)
222
dectoasc(decarr[i], buf, BUFSIZE-1, -1);
223
printf("%d: %s\n", i, buf);
225
PGTYPESdecimal_free(decarr[i]);
238
printf("(no errno set) - ");
240
case ECPG_INFORMIX_NUM_OVERFLOW:
241
printf("(errno == ECPG_INFORMIX_NUM_OVERFLOW) - ");
243
case ECPG_INFORMIX_NUM_UNDERFLOW:
244
printf("(errno == ECPG_INFORMIX_NUM_UNDERFLOW) - ");
246
case PGTYPES_NUM_OVERFLOW:
247
printf("(errno == PGTYPES_NUM_OVERFLOW) - ");
249
case PGTYPES_NUM_UNDERFLOW:
250
printf("(errno == PGTYPES_NUM_UNDERFLOW) - ");
252
case PGTYPES_NUM_BAD_NUMERIC:
253
printf("(errno == PGTYPES_NUM_BAD_NUMERIC) - ");
255
case PGTYPES_NUM_DIVIDE_ZERO:
256
printf("(errno == PGTYPES_NUM_DIVIDE_ZERO) - ");
259
printf("(unknown errno (%d))\n", errno);
260
printf("(libc: (%s)) ", strerror(errno));