1
/* Processed by ecpg (regression mode) */
2
/* These include files are added by the preprocessor */
6
/* End of automatic include section */
7
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
9
#line 1 "num_test2.pgc"
12
#include <pgtypes_numeric.h>
13
#include <pgtypes_error.h>
17
#line 1 "regression.h"
24
#line 7 "num_test2.pgc"
30
NOTE: This file has a different expect file for regression tests on MinGW32
35
char* nums[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4",
36
"2E-394", ".1E-2", "+.0", "-592.49E-07", "+32.84e-4",
37
".500001", "-.5000001",
38
"1234567890123456789012345678.91", /* 30 digits should fit
40
"1234567890123456789012345678.921", /* 31 digits should NOT
57
int i, j, k, q, r, count = 0;
59
numeric **numarr = (numeric **) calloc(1, sizeof(numeric));
63
for (i = 0; nums[i]; i++)
65
num = PGTYPESnumeric_from_asc(nums[i], &endptr);
66
if (!num) check_errno();
69
printf("endptr of %d is not NULL\n", i);
71
printf("*endptr of %d is not \\0\n", i);
75
numarr = realloc(numarr, sizeof(numeric *) * (count + 1));
76
numarr[count++] = num;
78
text = PGTYPESnumeric_to_asc(num, -1);
79
if (!text) check_errno();
80
printf("num[%d,1]: %s\n", i, text); free(text);
81
text = PGTYPESnumeric_to_asc(num, 0);
82
if (!text) check_errno();
83
printf("num[%d,2]: %s\n", i, text); free(text);
84
text = PGTYPESnumeric_to_asc(num, 1);
85
if (!text) check_errno();
86
printf("num[%d,3]: %s\n", i, text); free(text);
87
text = PGTYPESnumeric_to_asc(num, 2);
88
if (!text) check_errno();
89
printf("num[%d,4]: %s\n", i, text); free(text);
91
nin = PGTYPESnumeric_new();
92
text = PGTYPESnumeric_to_asc(nin, 2);
93
if (!text) check_errno();
94
printf("num[%d,5]: %s\n", i, text); free(text);
96
r = PGTYPESnumeric_to_long(num, &l);
98
printf("num[%d,6]: %ld (r: %d)\n", i, r?0L:l, r);
101
r = PGTYPESnumeric_from_long(l, nin);
102
if (r) check_errno();
103
text = PGTYPESnumeric_to_asc(nin, 2);
104
q = PGTYPESnumeric_cmp(num, nin);
105
printf("num[%d,7]: %s (r: %d - cmp: %d)\n", i, text, r, q);
109
r = PGTYPESnumeric_to_int(num, &k);
110
if (r) check_errno();
111
printf("num[%d,8]: %d (r: %d)\n", i, r?0:k, r);
114
r = PGTYPESnumeric_from_int(k, nin);
115
if (r) check_errno();
116
text = PGTYPESnumeric_to_asc(nin, 2);
117
q = PGTYPESnumeric_cmp(num, nin);
118
printf("num[%d,9]: %s (r: %d - cmp: %d)\n", i, text, r, q);
124
/* underflow does not work reliable on several archs, so not testing it here */
125
/* this is a libc problem since we only call strtod() */
127
r = PGTYPESnumeric_to_double(num, &d);
128
if (r) check_errno();
129
printf("num[%d,10]: %g (r: %d)\n", i, r?0.0:d, r);
132
/* do not test double to numeric because
133
* - extra digits are different on different architectures
134
* - PGTYPESnumeric_from_double internally calls PGTYPESnumeric_from_asc anyway
137
dec = PGTYPESdecimal_new();
138
r = PGTYPESnumeric_to_decimal(num, dec);
139
if (r) check_errno();
140
/* we have no special routine for outputting decimal, it would
141
* convert to a numeric anyway */
142
printf("num[%d,11]: - (r: %d)\n", i, r);
145
r = PGTYPESnumeric_from_decimal(dec, nin);
146
if (r) check_errno();
147
text = PGTYPESnumeric_to_asc(nin, 2);
148
q = PGTYPESnumeric_cmp(num, nin);
149
printf("num[%d,12]: %s (r: %d - cmp: %d)\n", i, text, r, q);
153
PGTYPESdecimal_free(dec);
154
PGTYPESnumeric_free(nin);
158
for (i = 0; i < count; i++)
160
for (j = 0; j < count; j++)
162
numeric* a = PGTYPESnumeric_new();
163
numeric* s = PGTYPESnumeric_new();
164
numeric* m = PGTYPESnumeric_new();
165
numeric* d = PGTYPESnumeric_new();
166
r = PGTYPESnumeric_add(numarr[i], numarr[j], a);
170
printf("r: %d\n", r);
174
text = PGTYPESnumeric_to_asc(a, 10);
175
printf("num[a,%d,%d]: %s\n", i, j, text);
178
r = PGTYPESnumeric_sub(numarr[i], numarr[j], s);
182
printf("r: %d\n", r);
186
text = PGTYPESnumeric_to_asc(s, 10);
187
printf("num[s,%d,%d]: %s\n", i, j, text);
190
r = PGTYPESnumeric_mul(numarr[i], numarr[j], m);
194
printf("r: %d\n", r);
198
text = PGTYPESnumeric_to_asc(m, 10);
199
printf("num[m,%d,%d]: %s\n", i, j, text);
202
r = PGTYPESnumeric_div(numarr[i], numarr[j], d);
206
printf("r: %d\n", r);
210
text = PGTYPESnumeric_to_asc(d, 10);
211
printf("num[d,%d,%d]: %s\n", i, j, text);
215
PGTYPESnumeric_free(a);
216
PGTYPESnumeric_free(s);
217
PGTYPESnumeric_free(m);
218
PGTYPESnumeric_free(d);
222
for (i = 0; i < count; i++)
224
text = PGTYPESnumeric_to_asc(numarr[i], -1);
225
printf("%d: %s\n", i, text);
227
PGTYPESnumeric_free(numarr[i]);
240
printf("(no errno set) - ");
242
case PGTYPES_NUM_OVERFLOW:
243
printf("(errno == PGTYPES_NUM_OVERFLOW) - ");
245
case PGTYPES_NUM_UNDERFLOW:
246
printf("(errno == PGTYPES_NUM_UNDERFLOW) - ");
248
case PGTYPES_NUM_BAD_NUMERIC:
249
printf("(errno == PGTYPES_NUM_BAD_NUMERIC) - ");
251
case PGTYPES_NUM_DIVIDE_ZERO:
252
printf("(errno == PGTYPES_NUM_DIVIDE_ZERO) - ");
255
printf("(unknown errno (%d))\n", errno);
256
printf("(libc: (%s)) ", strerror(errno));