00001
00002
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008
00009 #line 1 "nan_test.pgc"
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <float.h>
00013 #include <math.h>
00014 #include <pgtypes_numeric.h>
00015 #include <decimal.h>
00016
00017
00018 #line 1 "regression.h"
00019
00020
00021
00022
00023
00024
00025 #line 8 "nan_test.pgc"
00026
00027
00028 #ifdef WIN32
00029 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
00030 #define isnan(x) _isnan(x)
00031 #endif
00032
00033 int
00034 main(void)
00035 {
00036
00037
00038
00039
00040
00041
00042 #line 19 "nan_test.pgc"
00043 int id ;
00044
00045 #line 20 "nan_test.pgc"
00046 double d ;
00047
00048 #line 21 "nan_test.pgc"
00049 numeric * num ;
00050
00051 #line 22 "nan_test.pgc"
00052 char val [ 16 ] ;
00053
00054 #line 23 "nan_test.pgc"
00055
00056
00057 ECPGdebug(1, stderr);
00058
00059 #line 26 "nan_test.pgc"
00060
00061
00062 { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0);
00063 #line 28 "nan_test.pgc"
00064
00065 if (sqlca.sqlcode < 0) sqlprint ( );}
00066 #line 28 "nan_test.pgc"
00067
00068
00069 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table nantest1 ( id int4 , d float8 )", ECPGt_EOIT, ECPGt_EORT);
00070 #line 30 "nan_test.pgc"
00071
00072 if (sqlca.sqlcode < 0) sqlprint ( );}
00073 #line 30 "nan_test.pgc"
00074
00075 { 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);
00076 #line 31 "nan_test.pgc"
00077
00078 if (sqlca.sqlcode < 0) sqlprint ( );}
00079 #line 31 "nan_test.pgc"
00080
00081
00082
00083 #line 33 "nan_test.pgc"
00084
00085 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
00086 #line 34 "nan_test.pgc"
00087
00088 if (sqlca.sqlcode < 0) sqlprint ( );}
00089 #line 34 "nan_test.pgc"
00090
00091 while (1)
00092 {
00093 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
00094 ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
00095 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00096 ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
00097 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00098 ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
00099 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00100 #line 37 "nan_test.pgc"
00101
00102 if (sqlca.sqlcode < 0) sqlprint ( );}
00103 #line 37 "nan_test.pgc"
00104
00105 if (sqlca.sqlcode)
00106 break;
00107 if (isnan(d))
00108 printf("%d NaN '%s'\n", id, val);
00109 else if (isinf(d))
00110 printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
00111
00112 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( $1 + 3 , $2 )",
00113 ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
00114 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00115 ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
00116 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00117 #line 45 "nan_test.pgc"
00118
00119 if (sqlca.sqlcode < 0) sqlprint ( );}
00120 #line 45 "nan_test.pgc"
00121
00122 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( $1 + 6 , $2 )",
00123 ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
00124 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00125 ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
00126 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00127 #line 46 "nan_test.pgc"
00128
00129 if (sqlca.sqlcode < 0) sqlprint ( );}
00130 #line 46 "nan_test.pgc"
00131
00132 }
00133 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
00134 #line 48 "nan_test.pgc"
00135
00136 if (sqlca.sqlcode < 0) sqlprint ( );}
00137 #line 48 "nan_test.pgc"
00138
00139
00140 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
00141 #line 50 "nan_test.pgc"
00142
00143 if (sqlca.sqlcode < 0) sqlprint ( );}
00144 #line 50 "nan_test.pgc"
00145
00146 while (1)
00147 {
00148 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
00149 ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
00150 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00151 ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
00152 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00153 ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
00154 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00155 #line 53 "nan_test.pgc"
00156
00157 if (sqlca.sqlcode < 0) sqlprint ( );}
00158 #line 53 "nan_test.pgc"
00159
00160 if (sqlca.sqlcode)
00161 break;
00162 if (isinf(d))
00163 printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
00164 if (isnan(d))
00165 printf("%d NaN '%s'\n", id, val);
00166 }
00167 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
00168 #line 61 "nan_test.pgc"
00169
00170 if (sqlca.sqlcode < 0) sqlprint ( );}
00171 #line 61 "nan_test.pgc"
00172
00173
00174 num = PGTYPESnumeric_new();
00175
00176 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table nantest2 ( id int4 , d numeric )", ECPGt_EOIT, ECPGt_EORT);
00177 #line 65 "nan_test.pgc"
00178
00179 if (sqlca.sqlcode < 0) sqlprint ( );}
00180 #line 65 "nan_test.pgc"
00181
00182 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 4 , 'nan' :: numeric )", ECPGt_EOIT, ECPGt_EORT);
00183 #line 66 "nan_test.pgc"
00184
00185 if (sqlca.sqlcode < 0) sqlprint ( );}
00186 #line 66 "nan_test.pgc"
00187
00188
00189 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select id , d , d from nantest2 where id = 4", ECPGt_EOIT,
00190 ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
00191 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00192 ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
00193 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00194 ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
00195 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00196 #line 68 "nan_test.pgc"
00197
00198 if (sqlca.sqlcode < 0) sqlprint ( );}
00199 #line 68 "nan_test.pgc"
00200
00201
00202 printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
00203
00204 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 5 , $1 )",
00205 ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
00206 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00207 #line 72 "nan_test.pgc"
00208
00209 if (sqlca.sqlcode < 0) sqlprint ( );}
00210 #line 72 "nan_test.pgc"
00211
00212 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 6 , $1 )",
00213 ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
00214 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00215 #line 73 "nan_test.pgc"
00216
00217 if (sqlca.sqlcode < 0) sqlprint ( );}
00218 #line 73 "nan_test.pgc"
00219
00220
00221
00222 #line 75 "nan_test.pgc"
00223
00224 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for select id , d , d from nantest2", ECPGt_EOIT, ECPGt_EORT);
00225 #line 76 "nan_test.pgc"
00226
00227 if (sqlca.sqlcode < 0) sqlprint ( );}
00228 #line 76 "nan_test.pgc"
00229
00230 while (1)
00231 {
00232 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur1", ECPGt_EOIT,
00233 ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
00234 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00235 ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
00236 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
00237 ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
00238 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00239 #line 79 "nan_test.pgc"
00240
00241 if (sqlca.sqlcode < 0) sqlprint ( );}
00242 #line 79 "nan_test.pgc"
00243
00244 if (sqlca.sqlcode)
00245 break;
00246 printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
00247 }
00248 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
00249 #line 84 "nan_test.pgc"
00250
00251 if (sqlca.sqlcode < 0) sqlprint ( );}
00252 #line 84 "nan_test.pgc"
00253
00254
00255 PGTYPESnumeric_free(num);
00256
00257 { ECPGtrans(__LINE__, NULL, "rollback");
00258 #line 88 "nan_test.pgc"
00259
00260 if (sqlca.sqlcode < 0) sqlprint ( );}
00261 #line 88 "nan_test.pgc"
00262
00263 { ECPGdisconnect(__LINE__, "CURRENT");
00264 #line 89 "nan_test.pgc"
00265
00266 if (sqlca.sqlcode < 0) sqlprint ( );}
00267 #line 89 "nan_test.pgc"
00268
00269
00270 return (0);
00271 }