1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
3 #include <ecpglib.h>
4 #include <ecpgerrno.h>
5 #include <sqlca.h>
6 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8 
9 #line 1 "nan_test.pgc"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <float.h>
13 #include <math.h>
14 #include <pgtypes_numeric.h>
15 #include <decimal.h>
16 
17 
18 #line 1 "regression.h"
19 
20 
21 
22 
23 
24 
25 #line 8 "nan_test.pgc"
26 
27 
28 #ifdef WIN32
29 #if (_MSC_VER < 1800)
30 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
31 #define isnan(x) _isnan(x)
32 #endif
33 #endif   /* WIN32 */
34 
35 int
main(void)36 main(void)
37 {
38 	/* exec sql begin declare section */
39 
40 
41 
42 
43 
44 #line 21 "nan_test.pgc"
45  int id , loopcount ;
46 
47 #line 22 "nan_test.pgc"
48  double d ;
49 
50 #line 23 "nan_test.pgc"
51  numeric * num ;
52 
53 #line 24 "nan_test.pgc"
54  char val [ 16 ] ;
55 /* exec sql end declare section */
56 #line 25 "nan_test.pgc"
57 
58 
59 	ECPGdebug(1, stderr);
60 	/* exec sql whenever sqlerror  do sqlprint ( ) ; */
61 #line 28 "nan_test.pgc"
62 
63 
64 	{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
65 #line 30 "nan_test.pgc"
66 
67 if (sqlca.sqlcode < 0) sqlprint ( );}
68 #line 30 "nan_test.pgc"
69 
70 
71 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table nantest1 ( id int4 , d float8 )", ECPGt_EOIT, ECPGt_EORT);
72 #line 32 "nan_test.pgc"
73 
74 if (sqlca.sqlcode < 0) sqlprint ( );}
75 #line 32 "nan_test.pgc"
76 
77 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( 1 , 'nan' :: float8 ) , ( 2 , 'infinity' :: float8 ) , ( 3 , '-infinity' :: float8 )", ECPGt_EOIT, ECPGt_EORT);
78 #line 33 "nan_test.pgc"
79 
80 if (sqlca.sqlcode < 0) sqlprint ( );}
81 #line 33 "nan_test.pgc"
82 
83 
84 	/* declare cur cursor for select id , d , d from nantest1 */
85 #line 35 "nan_test.pgc"
86 
87 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
88 #line 36 "nan_test.pgc"
89 
90 if (sqlca.sqlcode < 0) sqlprint ( );}
91 #line 36 "nan_test.pgc"
92 
93 	for (loopcount = 0; loopcount < 100; loopcount++)
94 	{
95 		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
96 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
97 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
98 	ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
99 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
100 	ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
101 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
102 #line 39 "nan_test.pgc"
103 
104 if (sqlca.sqlcode < 0) sqlprint ( );}
105 #line 39 "nan_test.pgc"
106 
107 		if (sqlca.sqlcode)
108 			break;
109 		if (isnan(d))
110 			printf("%d  NaN '%s'\n", id, val);
111 		else if (isinf(d))
112 			printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
113 
114 		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( $1  + 3 , $2  )",
115 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
116 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
117 	ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
118 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
119 #line 47 "nan_test.pgc"
120 
121 if (sqlca.sqlcode < 0) sqlprint ( );}
122 #line 47 "nan_test.pgc"
123 
124 		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( $1  + 6 , $2  )",
125 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
126 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
127 	ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
128 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
129 #line 48 "nan_test.pgc"
130 
131 if (sqlca.sqlcode < 0) sqlprint ( );}
132 #line 48 "nan_test.pgc"
133 
134 	}
135 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
136 #line 50 "nan_test.pgc"
137 
138 if (sqlca.sqlcode < 0) sqlprint ( );}
139 #line 50 "nan_test.pgc"
140 
141 
142 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
143 #line 52 "nan_test.pgc"
144 
145 if (sqlca.sqlcode < 0) sqlprint ( );}
146 #line 52 "nan_test.pgc"
147 
148 	for (loopcount = 0; loopcount < 100; loopcount++)
149 	{
150 		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
151 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
152 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
153 	ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
154 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
155 	ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
156 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
157 #line 55 "nan_test.pgc"
158 
159 if (sqlca.sqlcode < 0) sqlprint ( );}
160 #line 55 "nan_test.pgc"
161 
162 		if (sqlca.sqlcode)
163 			break;
164 		if (isinf(d))
165 			printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
166 		if (isnan(d))
167 			printf("%d  NaN '%s'\n", id, val);
168 	}
169 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
170 #line 63 "nan_test.pgc"
171 
172 if (sqlca.sqlcode < 0) sqlprint ( );}
173 #line 63 "nan_test.pgc"
174 
175 
176 	num = PGTYPESnumeric_new();
177 
178 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table nantest2 ( id int4 , d numeric )", ECPGt_EOIT, ECPGt_EORT);
179 #line 67 "nan_test.pgc"
180 
181 if (sqlca.sqlcode < 0) sqlprint ( );}
182 #line 67 "nan_test.pgc"
183 
184 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 4 , 'nan' :: numeric )", ECPGt_EOIT, ECPGt_EORT);
185 #line 68 "nan_test.pgc"
186 
187 if (sqlca.sqlcode < 0) sqlprint ( );}
188 #line 68 "nan_test.pgc"
189 
190 
191 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select id , d , d from nantest2 where id = 4", ECPGt_EOIT,
192 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
193 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
194 	ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
195 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
196 	ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
197 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
198 #line 70 "nan_test.pgc"
199 
200 if (sqlca.sqlcode < 0) sqlprint ( );}
201 #line 70 "nan_test.pgc"
202 
203 
204 	printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
205 
206 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 5 , $1  )",
207 	ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
208 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
209 #line 74 "nan_test.pgc"
210 
211 if (sqlca.sqlcode < 0) sqlprint ( );}
212 #line 74 "nan_test.pgc"
213 
214 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 6 , $1  )",
215 	ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
216 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
217 #line 75 "nan_test.pgc"
218 
219 if (sqlca.sqlcode < 0) sqlprint ( );}
220 #line 75 "nan_test.pgc"
221 
222 
223 	/* declare cur1 cursor for select id , d , d from nantest2 */
224 #line 77 "nan_test.pgc"
225 
226 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for select id , d , d from nantest2", ECPGt_EOIT, ECPGt_EORT);
227 #line 78 "nan_test.pgc"
228 
229 if (sqlca.sqlcode < 0) sqlprint ( );}
230 #line 78 "nan_test.pgc"
231 
232 	for (loopcount = 0; loopcount < 100; loopcount++)
233 	{
234 		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur1", ECPGt_EOIT,
235 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
236 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
237 	ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
238 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
239 	ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
240 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
241 #line 81 "nan_test.pgc"
242 
243 if (sqlca.sqlcode < 0) sqlprint ( );}
244 #line 81 "nan_test.pgc"
245 
246 		if (sqlca.sqlcode)
247 			break;
248 		printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
249 	}
250 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
251 #line 86 "nan_test.pgc"
252 
253 if (sqlca.sqlcode < 0) sqlprint ( );}
254 #line 86 "nan_test.pgc"
255 
256 
257 	PGTYPESnumeric_free(num);
258 
259 	{ ECPGtrans(__LINE__, NULL, "rollback");
260 #line 90 "nan_test.pgc"
261 
262 if (sqlca.sqlcode < 0) sqlprint ( );}
263 #line 90 "nan_test.pgc"
264 
265 	{ ECPGdisconnect(__LINE__, "CURRENT");
266 #line 91 "nan_test.pgc"
267 
268 if (sqlca.sqlcode < 0) sqlprint ( );}
269 #line 91 "nan_test.pgc"
270 
271 
272 	return (0);
273 }
274