blob: e94f8c3418fde2adf8261199fe16fff86e303d24 [file] [log] [blame]
mistachkin69f3d042013-03-11 01:23:37 +00001# 2013 March 10
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
mistachkina17713f2013-08-29 02:27:39 +000011# This file implements regression tests for SQLite library. The focus of
12# this file is testing the tointeger() and toreal() functions.
13#
14# Several of the toreal() tests are disabled on platforms where floating
15# point precision is not high enough to represent their constant integer
16# expression arguments as double precision floating point values.
mistachkin69f3d042013-03-11 01:23:37 +000017#
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
mistachkin98ab33a2013-08-20 09:26:38 +000020set saved_tcl_precision $tcl_precision
21set tcl_precision 0
drh5f8cdac2013-10-14 21:14:42 +000022load_static_extension db totype
mistachkin69f3d042013-03-11 01:23:37 +000023
mistachkinaeddf192013-09-04 00:58:00 +000024set highPrecision(1) [expr \
drh5f8cdac2013-10-14 21:14:42 +000025 {[db eval {SELECT tointeger(9223372036854775807 + 1);}] eq {{}}}]
mistachkinaeddf192013-09-04 00:58:00 +000026
drh0057a742013-06-21 19:29:33 +000027do_execsql_test func4-1.1 {
mistachkin69f3d042013-03-11 01:23:37 +000028 SELECT tointeger(NULL);
29} {{}}
drh0057a742013-06-21 19:29:33 +000030do_execsql_test func4-1.2 {
mistachkin69f3d042013-03-11 01:23:37 +000031 SELECT tointeger('');
32} {{}}
drh0057a742013-06-21 19:29:33 +000033do_execsql_test func4-1.3 {
mistachkin69f3d042013-03-11 01:23:37 +000034 SELECT tointeger(' ');
35} {{}}
drh0057a742013-06-21 19:29:33 +000036do_execsql_test func4-1.4 {
mistachkin69f3d042013-03-11 01:23:37 +000037 SELECT tointeger('1234');
38} {1234}
drh0057a742013-06-21 19:29:33 +000039do_execsql_test func4-1.5 {
mistachkin69f3d042013-03-11 01:23:37 +000040 SELECT tointeger(' 1234');
mistachkin98ab33a2013-08-20 09:26:38 +000041} {{}}
drh0057a742013-06-21 19:29:33 +000042do_execsql_test func4-1.6 {
mistachkin69f3d042013-03-11 01:23:37 +000043 SELECT tointeger('bad');
44} {{}}
drh0057a742013-06-21 19:29:33 +000045do_execsql_test func4-1.7 {
mistachkin69f3d042013-03-11 01:23:37 +000046 SELECT tointeger('0xBAD');
47} {{}}
drh0057a742013-06-21 19:29:33 +000048do_execsql_test func4-1.8 {
mistachkin69f3d042013-03-11 01:23:37 +000049 SELECT tointeger('123BAD');
50} {{}}
drh0057a742013-06-21 19:29:33 +000051do_execsql_test func4-1.9 {
mistachkin69f3d042013-03-11 01:23:37 +000052 SELECT tointeger('0x123BAD');
53} {{}}
drh0057a742013-06-21 19:29:33 +000054do_execsql_test func4-1.10 {
mistachkin69f3d042013-03-11 01:23:37 +000055 SELECT tointeger('123NO');
56} {{}}
drh0057a742013-06-21 19:29:33 +000057do_execsql_test func4-1.11 {
mistachkin69f3d042013-03-11 01:23:37 +000058 SELECT tointeger('0x123NO');
59} {{}}
drh0057a742013-06-21 19:29:33 +000060do_execsql_test func4-1.12 {
mistachkin69f3d042013-03-11 01:23:37 +000061 SELECT tointeger('-0x1');
62} {{}}
drh0057a742013-06-21 19:29:33 +000063do_execsql_test func4-1.13 {
mistachkin69f3d042013-03-11 01:23:37 +000064 SELECT tointeger('-0x0');
65} {{}}
drh0057a742013-06-21 19:29:33 +000066do_execsql_test func4-1.14 {
mistachkin69f3d042013-03-11 01:23:37 +000067 SELECT tointeger('0x0');
68} {{}}
drh0057a742013-06-21 19:29:33 +000069do_execsql_test func4-1.15 {
mistachkin69f3d042013-03-11 01:23:37 +000070 SELECT tointeger('0x1');
71} {{}}
drh0057a742013-06-21 19:29:33 +000072do_execsql_test func4-1.16 {
mistachkin69f3d042013-03-11 01:23:37 +000073 SELECT tointeger(-1);
74} {-1}
drh0057a742013-06-21 19:29:33 +000075do_execsql_test func4-1.17 {
mistachkin69f3d042013-03-11 01:23:37 +000076 SELECT tointeger(-0);
77} {0}
drh0057a742013-06-21 19:29:33 +000078do_execsql_test func4-1.18 {
mistachkin69f3d042013-03-11 01:23:37 +000079 SELECT tointeger(0);
80} {0}
drh0057a742013-06-21 19:29:33 +000081do_execsql_test func4-1.19 {
mistachkin69f3d042013-03-11 01:23:37 +000082 SELECT tointeger(1);
83} {1}
drh0057a742013-06-21 19:29:33 +000084do_execsql_test func4-1.20 {
mistachkin69f3d042013-03-11 01:23:37 +000085 SELECT tointeger(-1.79769313486232e308 - 1);
mistachkinee1c64e2013-03-12 09:07:25 +000086} {{}}
drh0057a742013-06-21 19:29:33 +000087do_execsql_test func4-1.21 {
mistachkin69f3d042013-03-11 01:23:37 +000088 SELECT tointeger(-1.79769313486232e308);
mistachkinee1c64e2013-03-12 09:07:25 +000089} {{}}
drh0057a742013-06-21 19:29:33 +000090do_execsql_test func4-1.22 {
mistachkin69f3d042013-03-11 01:23:37 +000091 SELECT tointeger(-1.79769313486232e308 + 1);
mistachkinee1c64e2013-03-12 09:07:25 +000092} {{}}
drh0057a742013-06-21 19:29:33 +000093do_execsql_test func4-1.23 {
mistachkin69f3d042013-03-11 01:23:37 +000094 SELECT tointeger(-9223372036854775808 - 1);
95} {-9223372036854775808}
drh0057a742013-06-21 19:29:33 +000096do_execsql_test func4-1.24 {
mistachkin69f3d042013-03-11 01:23:37 +000097 SELECT tointeger(-9223372036854775808);
98} {-9223372036854775808}
drh0057a742013-06-21 19:29:33 +000099do_execsql_test func4-1.25 {
mistachkin69f3d042013-03-11 01:23:37 +0000100 SELECT tointeger(-9223372036854775808 + 1);
101} {-9223372036854775807}
drh0057a742013-06-21 19:29:33 +0000102do_execsql_test func4-1.26 {
mistachkin98ab33a2013-08-20 09:26:38 +0000103 SELECT tointeger(-9223372036854775807 - 1);
104} {-9223372036854775808}
105do_execsql_test func4-1.27 {
106 SELECT tointeger(-9223372036854775807);
107} {-9223372036854775807}
108do_execsql_test func4-1.28 {
109 SELECT tointeger(-9223372036854775807 + 1);
110} {-9223372036854775806}
111do_execsql_test func4-1.29 {
mistachkin69f3d042013-03-11 01:23:37 +0000112 SELECT tointeger(-2147483648 - 1);
113} {-2147483649}
mistachkin98ab33a2013-08-20 09:26:38 +0000114do_execsql_test func4-1.30 {
mistachkin69f3d042013-03-11 01:23:37 +0000115 SELECT tointeger(-2147483648);
116} {-2147483648}
mistachkin98ab33a2013-08-20 09:26:38 +0000117do_execsql_test func4-1.31 {
mistachkin69f3d042013-03-11 01:23:37 +0000118 SELECT tointeger(-2147483648 + 1);
119} {-2147483647}
mistachkin98ab33a2013-08-20 09:26:38 +0000120do_execsql_test func4-1.32 {
mistachkin69f3d042013-03-11 01:23:37 +0000121 SELECT tointeger(2147483647 - 1);
122} {2147483646}
mistachkin98ab33a2013-08-20 09:26:38 +0000123do_execsql_test func4-1.33 {
mistachkin69f3d042013-03-11 01:23:37 +0000124 SELECT tointeger(2147483647);
125} {2147483647}
mistachkin98ab33a2013-08-20 09:26:38 +0000126do_execsql_test func4-1.34 {
mistachkin69f3d042013-03-11 01:23:37 +0000127 SELECT tointeger(2147483647 + 1);
128} {2147483648}
mistachkin98ab33a2013-08-20 09:26:38 +0000129do_execsql_test func4-1.35 {
mistachkin69f3d042013-03-11 01:23:37 +0000130 SELECT tointeger(9223372036854775807 - 1);
131} {9223372036854775806}
mistachkin98ab33a2013-08-20 09:26:38 +0000132do_execsql_test func4-1.36 {
mistachkin69f3d042013-03-11 01:23:37 +0000133 SELECT tointeger(9223372036854775807);
134} {9223372036854775807}
mistachkinaeddf192013-09-04 00:58:00 +0000135if {$highPrecision(1)} {
136 do_execsql_test func4-1.37 {
137 SELECT tointeger(9223372036854775807 + 1);
138 } {{}}
139}
mistachkin98ab33a2013-08-20 09:26:38 +0000140do_execsql_test func4-1.38 {
mistachkin69f3d042013-03-11 01:23:37 +0000141 SELECT tointeger(1.79769313486232e308 - 1);
mistachkinee1c64e2013-03-12 09:07:25 +0000142} {{}}
mistachkin98ab33a2013-08-20 09:26:38 +0000143do_execsql_test func4-1.39 {
mistachkin69f3d042013-03-11 01:23:37 +0000144 SELECT tointeger(1.79769313486232e308);
mistachkinee1c64e2013-03-12 09:07:25 +0000145} {{}}
mistachkin98ab33a2013-08-20 09:26:38 +0000146do_execsql_test func4-1.40 {
mistachkin69f3d042013-03-11 01:23:37 +0000147 SELECT tointeger(1.79769313486232e308 + 1);
mistachkinee1c64e2013-03-12 09:07:25 +0000148} {{}}
mistachkin98ab33a2013-08-20 09:26:38 +0000149do_execsql_test func4-1.41 {
mistachkin69f3d042013-03-11 01:23:37 +0000150 SELECT tointeger(4503599627370496 - 1);
151} {4503599627370495}
mistachkin98ab33a2013-08-20 09:26:38 +0000152do_execsql_test func4-1.42 {
mistachkin69f3d042013-03-11 01:23:37 +0000153 SELECT tointeger(4503599627370496);
154} {4503599627370496}
mistachkin98ab33a2013-08-20 09:26:38 +0000155do_execsql_test func4-1.43 {
mistachkin69f3d042013-03-11 01:23:37 +0000156 SELECT tointeger(4503599627370496 + 1);
157} {4503599627370497}
mistachkin98ab33a2013-08-20 09:26:38 +0000158do_execsql_test func4-1.44 {
mistachkin69f3d042013-03-11 01:23:37 +0000159 SELECT tointeger(9007199254740992 - 1);
160} {9007199254740991}
mistachkin98ab33a2013-08-20 09:26:38 +0000161do_execsql_test func4-1.45 {
mistachkin69f3d042013-03-11 01:23:37 +0000162 SELECT tointeger(9007199254740992);
163} {9007199254740992}
mistachkin98ab33a2013-08-20 09:26:38 +0000164do_execsql_test func4-1.46 {
mistachkin69f3d042013-03-11 01:23:37 +0000165 SELECT tointeger(9007199254740992 + 1);
166} {9007199254740993}
mistachkin98ab33a2013-08-20 09:26:38 +0000167do_execsql_test func4-1.47 {
168 SELECT tointeger(9223372036854775807 - 1);
169} {9223372036854775806}
170do_execsql_test func4-1.48 {
171 SELECT tointeger(9223372036854775807);
172} {9223372036854775807}
mistachkinaeddf192013-09-04 00:58:00 +0000173if {$highPrecision(1)} {
174 do_execsql_test func4-1.49 {
175 SELECT tointeger(9223372036854775807 + 1);
176 } {{}}
177 do_execsql_test func4-1.50 {
178 SELECT tointeger(9223372036854775808 - 1);
179 } {{}}
180 do_execsql_test func4-1.51 {
181 SELECT tointeger(9223372036854775808);
182 } {{}}
183 do_execsql_test func4-1.52 {
184 SELECT tointeger(9223372036854775808 + 1);
185 } {{}}
186}
mistachkin98ab33a2013-08-20 09:26:38 +0000187do_execsql_test func4-1.53 {
mistachkin69f3d042013-03-11 01:23:37 +0000188 SELECT tointeger(18446744073709551616 - 1);
mistachkinee1c64e2013-03-12 09:07:25 +0000189} {{}}
mistachkin98ab33a2013-08-20 09:26:38 +0000190do_execsql_test func4-1.54 {
mistachkin69f3d042013-03-11 01:23:37 +0000191 SELECT tointeger(18446744073709551616);
mistachkinee1c64e2013-03-12 09:07:25 +0000192} {{}}
mistachkin98ab33a2013-08-20 09:26:38 +0000193do_execsql_test func4-1.55 {
mistachkin69f3d042013-03-11 01:23:37 +0000194 SELECT tointeger(18446744073709551616 + 1);
mistachkinee1c64e2013-03-12 09:07:25 +0000195} {{}}
mistachkin69f3d042013-03-11 01:23:37 +0000196
197ifcapable floatingpoint {
mistachkinaeddf192013-09-04 00:58:00 +0000198 set highPrecision(2) [expr \
drh5f8cdac2013-10-14 21:14:42 +0000199 {[db eval {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}]
mistachkina17713f2013-08-29 02:27:39 +0000200
drh0057a742013-06-21 19:29:33 +0000201 do_execsql_test func4-2.1 {
mistachkinbc3ec282013-03-13 06:48:05 +0000202 SELECT toreal(NULL);
mistachkin69f3d042013-03-11 01:23:37 +0000203 } {{}}
drh0057a742013-06-21 19:29:33 +0000204 do_execsql_test func4-2.2 {
mistachkinbc3ec282013-03-13 06:48:05 +0000205 SELECT toreal('');
mistachkin69f3d042013-03-11 01:23:37 +0000206 } {{}}
drh0057a742013-06-21 19:29:33 +0000207 do_execsql_test func4-2.3 {
mistachkinbc3ec282013-03-13 06:48:05 +0000208 SELECT toreal(' ');
mistachkin69f3d042013-03-11 01:23:37 +0000209 } {{}}
drh0057a742013-06-21 19:29:33 +0000210 do_execsql_test func4-2.4 {
mistachkinbc3ec282013-03-13 06:48:05 +0000211 SELECT toreal('1234');
mistachkin69f3d042013-03-11 01:23:37 +0000212 } {1234.0}
drh0057a742013-06-21 19:29:33 +0000213 do_execsql_test func4-2.5 {
mistachkinbc3ec282013-03-13 06:48:05 +0000214 SELECT toreal(' 1234');
mistachkin98ab33a2013-08-20 09:26:38 +0000215 } {{}}
drh0057a742013-06-21 19:29:33 +0000216 do_execsql_test func4-2.6 {
mistachkinbc3ec282013-03-13 06:48:05 +0000217 SELECT toreal('bad');
mistachkin69f3d042013-03-11 01:23:37 +0000218 } {{}}
drh0057a742013-06-21 19:29:33 +0000219 do_execsql_test func4-2.7 {
mistachkinbc3ec282013-03-13 06:48:05 +0000220 SELECT toreal('0xBAD');
mistachkin69f3d042013-03-11 01:23:37 +0000221 } {{}}
drh0057a742013-06-21 19:29:33 +0000222 do_execsql_test func4-2.8 {
mistachkinbc3ec282013-03-13 06:48:05 +0000223 SELECT toreal('123BAD');
mistachkin69f3d042013-03-11 01:23:37 +0000224 } {{}}
drh0057a742013-06-21 19:29:33 +0000225 do_execsql_test func4-2.9 {
mistachkinbc3ec282013-03-13 06:48:05 +0000226 SELECT toreal('0x123BAD');
mistachkin69f3d042013-03-11 01:23:37 +0000227 } {{}}
drh0057a742013-06-21 19:29:33 +0000228 do_execsql_test func4-2.10 {
mistachkinbc3ec282013-03-13 06:48:05 +0000229 SELECT toreal('123NO');
mistachkin69f3d042013-03-11 01:23:37 +0000230 } {{}}
drh0057a742013-06-21 19:29:33 +0000231 do_execsql_test func4-2.11 {
mistachkinbc3ec282013-03-13 06:48:05 +0000232 SELECT toreal('0x123NO');
mistachkin69f3d042013-03-11 01:23:37 +0000233 } {{}}
drh0057a742013-06-21 19:29:33 +0000234 do_execsql_test func4-2.12 {
mistachkinbc3ec282013-03-13 06:48:05 +0000235 SELECT toreal('-0x1');
mistachkin69f3d042013-03-11 01:23:37 +0000236 } {{}}
drh0057a742013-06-21 19:29:33 +0000237 do_execsql_test func4-2.13 {
mistachkinbc3ec282013-03-13 06:48:05 +0000238 SELECT toreal('-0x0');
mistachkin69f3d042013-03-11 01:23:37 +0000239 } {{}}
drh0057a742013-06-21 19:29:33 +0000240 do_execsql_test func4-2.14 {
mistachkinbc3ec282013-03-13 06:48:05 +0000241 SELECT toreal('0x0');
mistachkin69f3d042013-03-11 01:23:37 +0000242 } {{}}
drh0057a742013-06-21 19:29:33 +0000243 do_execsql_test func4-2.15 {
mistachkinbc3ec282013-03-13 06:48:05 +0000244 SELECT toreal('0x1');
mistachkin69f3d042013-03-11 01:23:37 +0000245 } {{}}
drh0057a742013-06-21 19:29:33 +0000246 do_execsql_test func4-2.16 {
mistachkinbc3ec282013-03-13 06:48:05 +0000247 SELECT toreal(-1);
mistachkin69f3d042013-03-11 01:23:37 +0000248 } {-1.0}
drh0057a742013-06-21 19:29:33 +0000249 do_execsql_test func4-2.17 {
mistachkinbc3ec282013-03-13 06:48:05 +0000250 SELECT toreal(-0);
mistachkin69f3d042013-03-11 01:23:37 +0000251 } {0.0}
drh0057a742013-06-21 19:29:33 +0000252 do_execsql_test func4-2.18 {
mistachkinbc3ec282013-03-13 06:48:05 +0000253 SELECT toreal(0);
mistachkin69f3d042013-03-11 01:23:37 +0000254 } {0.0}
drh0057a742013-06-21 19:29:33 +0000255 do_execsql_test func4-2.19 {
mistachkinbc3ec282013-03-13 06:48:05 +0000256 SELECT toreal(1);
mistachkin69f3d042013-03-11 01:23:37 +0000257 } {1.0}
drh0057a742013-06-21 19:29:33 +0000258 do_execsql_test func4-2.20 {
mistachkinbc3ec282013-03-13 06:48:05 +0000259 SELECT toreal(-1.79769313486232e308 - 1);
mistachkin69f3d042013-03-11 01:23:37 +0000260 } {-Inf}
drh0057a742013-06-21 19:29:33 +0000261 do_execsql_test func4-2.21 {
mistachkinbc3ec282013-03-13 06:48:05 +0000262 SELECT toreal(-1.79769313486232e308);
mistachkin69f3d042013-03-11 01:23:37 +0000263 } {-Inf}
drh0057a742013-06-21 19:29:33 +0000264 do_execsql_test func4-2.22 {
mistachkinbc3ec282013-03-13 06:48:05 +0000265 SELECT toreal(-1.79769313486232e308 + 1);
mistachkin69f3d042013-03-11 01:23:37 +0000266 } {-Inf}
drh0057a742013-06-21 19:29:33 +0000267 do_execsql_test func4-2.23 {
mistachkinbc3ec282013-03-13 06:48:05 +0000268 SELECT toreal(-9223372036854775808 - 1);
mistachkin98ab33a2013-08-20 09:26:38 +0000269 } {-9.223372036854776e+18}
drh0057a742013-06-21 19:29:33 +0000270 do_execsql_test func4-2.24 {
mistachkinbc3ec282013-03-13 06:48:05 +0000271 SELECT toreal(-9223372036854775808);
mistachkin98ab33a2013-08-20 09:26:38 +0000272 } {-9.223372036854776e+18}
mistachkinaeddf192013-09-04 00:58:00 +0000273 if {$highPrecision(2)} {
mistachkina17713f2013-08-29 02:27:39 +0000274 do_execsql_test func4-2.25 {
275 SELECT toreal(-9223372036854775808 + 1);
276 } {{}}
277 }
drh0057a742013-06-21 19:29:33 +0000278 do_execsql_test func4-2.26 {
mistachkin98ab33a2013-08-20 09:26:38 +0000279 SELECT toreal(-9223372036854775807 - 1);
280 } {-9.223372036854776e+18}
mistachkinaeddf192013-09-04 00:58:00 +0000281 if {$highPrecision(2)} {
mistachkina17713f2013-08-29 02:27:39 +0000282 do_execsql_test func4-2.27 {
283 SELECT toreal(-9223372036854775807);
284 } {{}}
285 do_execsql_test func4-2.28 {
286 SELECT toreal(-9223372036854775807 + 1);
287 } {{}}
288 }
mistachkin98ab33a2013-08-20 09:26:38 +0000289 do_execsql_test func4-2.29 {
mistachkinbc3ec282013-03-13 06:48:05 +0000290 SELECT toreal(-2147483648 - 1);
mistachkin69f3d042013-03-11 01:23:37 +0000291 } {-2147483649.0}
mistachkin98ab33a2013-08-20 09:26:38 +0000292 do_execsql_test func4-2.30 {
mistachkinbc3ec282013-03-13 06:48:05 +0000293 SELECT toreal(-2147483648);
mistachkin69f3d042013-03-11 01:23:37 +0000294 } {-2147483648.0}
mistachkin98ab33a2013-08-20 09:26:38 +0000295 do_execsql_test func4-2.31 {
mistachkinbc3ec282013-03-13 06:48:05 +0000296 SELECT toreal(-2147483648 + 1);
mistachkin69f3d042013-03-11 01:23:37 +0000297 } {-2147483647.0}
mistachkin98ab33a2013-08-20 09:26:38 +0000298 do_execsql_test func4-2.32 {
mistachkinbc3ec282013-03-13 06:48:05 +0000299 SELECT toreal(2147483647 - 1);
mistachkin69f3d042013-03-11 01:23:37 +0000300 } {2147483646.0}
mistachkin98ab33a2013-08-20 09:26:38 +0000301 do_execsql_test func4-2.33 {
mistachkinbc3ec282013-03-13 06:48:05 +0000302 SELECT toreal(2147483647);
mistachkin69f3d042013-03-11 01:23:37 +0000303 } {2147483647.0}
mistachkin98ab33a2013-08-20 09:26:38 +0000304 do_execsql_test func4-2.34 {
mistachkinbc3ec282013-03-13 06:48:05 +0000305 SELECT toreal(2147483647 + 1);
mistachkin69f3d042013-03-11 01:23:37 +0000306 } {2147483648.0}
mistachkinaeddf192013-09-04 00:58:00 +0000307 if {$highPrecision(2)} {
mistachkina17713f2013-08-29 02:27:39 +0000308 do_execsql_test func4-2.35 {
309 SELECT toreal(9223372036854775807 - 1);
310 } {{}}
mistachkinaeddf192013-09-04 00:58:00 +0000311 if {$highPrecision(1)} {
312 do_execsql_test func4-2.36 {
313 SELECT toreal(9223372036854775807);
314 } {{}}
315 }
mistachkina17713f2013-08-29 02:27:39 +0000316 }
mistachkin98ab33a2013-08-20 09:26:38 +0000317 do_execsql_test func4-2.37 {
318 SELECT toreal(9223372036854775807 + 1);
319 } {9.223372036854776e+18}
320 do_execsql_test func4-2.38 {
mistachkinbc3ec282013-03-13 06:48:05 +0000321 SELECT toreal(1.79769313486232e308 - 1);
mistachkin69f3d042013-03-11 01:23:37 +0000322 } {Inf}
mistachkin98ab33a2013-08-20 09:26:38 +0000323 do_execsql_test func4-2.39 {
mistachkinbc3ec282013-03-13 06:48:05 +0000324 SELECT toreal(1.79769313486232e308);
mistachkin69f3d042013-03-11 01:23:37 +0000325 } {Inf}
mistachkin98ab33a2013-08-20 09:26:38 +0000326 do_execsql_test func4-2.40 {
mistachkinbc3ec282013-03-13 06:48:05 +0000327 SELECT toreal(1.79769313486232e308 + 1);
mistachkin69f3d042013-03-11 01:23:37 +0000328 } {Inf}
drh0057a742013-06-21 19:29:33 +0000329 do_execsql_test func4-2.41 {
mistachkin98ab33a2013-08-20 09:26:38 +0000330 SELECT toreal(4503599627370496 - 1);
331 } {4503599627370495.0}
drh0057a742013-06-21 19:29:33 +0000332 do_execsql_test func4-2.42 {
mistachkin98ab33a2013-08-20 09:26:38 +0000333 SELECT toreal(4503599627370496);
334 } {4503599627370496.0}
drh0057a742013-06-21 19:29:33 +0000335 do_execsql_test func4-2.43 {
mistachkin98ab33a2013-08-20 09:26:38 +0000336 SELECT toreal(4503599627370496 + 1);
337 } {4503599627370497.0}
drh0057a742013-06-21 19:29:33 +0000338 do_execsql_test func4-2.44 {
mistachkin98ab33a2013-08-20 09:26:38 +0000339 SELECT toreal(9007199254740992 - 1);
340 } {9007199254740991.0}
drh0057a742013-06-21 19:29:33 +0000341 do_execsql_test func4-2.45 {
mistachkin98ab33a2013-08-20 09:26:38 +0000342 SELECT toreal(9007199254740992);
343 } {9007199254740992.0}
mistachkinaeddf192013-09-04 00:58:00 +0000344 if {$highPrecision(2)} {
mistachkina17713f2013-08-29 02:27:39 +0000345 do_execsql_test func4-2.46 {
346 SELECT toreal(9007199254740992 + 1);
347 } {{}}
348 }
drh0057a742013-06-21 19:29:33 +0000349 do_execsql_test func4-2.47 {
mistachkin98ab33a2013-08-20 09:26:38 +0000350 SELECT toreal(9007199254740992 + 2);
351 } {9007199254740994.0}
drh0057a742013-06-21 19:29:33 +0000352 do_execsql_test func4-2.48 {
mistachkin98ab33a2013-08-20 09:26:38 +0000353 SELECT toreal(tointeger(9223372036854775808) - 1);
354 } {{}}
mistachkinaeddf192013-09-04 00:58:00 +0000355 if {$highPrecision(1)} {
356 do_execsql_test func4-2.49 {
357 SELECT toreal(tointeger(9223372036854775808));
358 } {{}}
359 do_execsql_test func4-2.50 {
360 SELECT toreal(tointeger(9223372036854775808) + 1);
361 } {{}}
362 }
mistachkin98ab33a2013-08-20 09:26:38 +0000363 do_execsql_test func4-2.51 {
364 SELECT toreal(tointeger(18446744073709551616) - 1);
365 } {{}}
366 do_execsql_test func4-2.52 {
367 SELECT toreal(tointeger(18446744073709551616));
368 } {{}}
369 do_execsql_test func4-2.53 {
370 SELECT toreal(tointeger(18446744073709551616) + 1);
371 } {{}}
mistachkin69f3d042013-03-11 01:23:37 +0000372}
373
mistachkin32be00a2013-03-11 06:24:46 +0000374ifcapable check {
drh0057a742013-06-21 19:29:33 +0000375 do_execsql_test func4-3.1 {
mistachkin32be00a2013-03-11 06:24:46 +0000376 CREATE TABLE t1(
mistachkin98ab33a2013-08-20 09:26:38 +0000377 x INTEGER CHECK(tointeger(x) IS NOT NULL)
mistachkin32be00a2013-03-11 06:24:46 +0000378 );
379 } {}
drh0057a742013-06-21 19:29:33 +0000380 do_test func4-3.2 {
mistachkin32be00a2013-03-11 06:24:46 +0000381 catchsql {
382 INSERT INTO t1 (x) VALUES (NULL);
383 }
drhf9c8ce32013-11-05 13:33:55 +0000384 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000385 do_test func4-3.3 {
mistachkin32be00a2013-03-11 06:24:46 +0000386 catchsql {
387 INSERT INTO t1 (x) VALUES (NULL);
388 }
drhf9c8ce32013-11-05 13:33:55 +0000389 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000390 do_test func4-3.4 {
mistachkin32be00a2013-03-11 06:24:46 +0000391 catchsql {
392 INSERT INTO t1 (x) VALUES ('');
393 }
drhf9c8ce32013-11-05 13:33:55 +0000394 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000395 do_test func4-3.5 {
mistachkin32be00a2013-03-11 06:24:46 +0000396 catchsql {
397 INSERT INTO t1 (x) VALUES ('bad');
398 }
drhf9c8ce32013-11-05 13:33:55 +0000399 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000400 do_test func4-3.6 {
mistachkin32be00a2013-03-11 06:24:46 +0000401 catchsql {
402 INSERT INTO t1 (x) VALUES ('1234bad');
403 }
drhf9c8ce32013-11-05 13:33:55 +0000404 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000405 do_test func4-3.7 {
mistachkin32be00a2013-03-11 06:24:46 +0000406 catchsql {
mistachkinee1c64e2013-03-12 09:07:25 +0000407 INSERT INTO t1 (x) VALUES ('1234.56bad');
408 }
drhf9c8ce32013-11-05 13:33:55 +0000409 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000410 do_test func4-3.8 {
mistachkinee1c64e2013-03-12 09:07:25 +0000411 catchsql {
mistachkin32be00a2013-03-11 06:24:46 +0000412 INSERT INTO t1 (x) VALUES (1234);
413 }
414 } {0 {}}
drh0057a742013-06-21 19:29:33 +0000415 do_test func4-3.9 {
mistachkin32be00a2013-03-11 06:24:46 +0000416 catchsql {
417 INSERT INTO t1 (x) VALUES (1234.56);
418 }
drhf9c8ce32013-11-05 13:33:55 +0000419 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000420 do_test func4-3.10 {
mistachkin32be00a2013-03-11 06:24:46 +0000421 catchsql {
422 INSERT INTO t1 (x) VALUES ('1234');
423 }
424 } {0 {}}
drh0057a742013-06-21 19:29:33 +0000425 do_test func4-3.11 {
mistachkin32be00a2013-03-11 06:24:46 +0000426 catchsql {
427 INSERT INTO t1 (x) VALUES ('1234.56');
428 }
drhf9c8ce32013-11-05 13:33:55 +0000429 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000430 do_test func4-3.12 {
mistachkin32be00a2013-03-11 06:24:46 +0000431 catchsql {
432 INSERT INTO t1 (x) VALUES (ZEROBLOB(4));
433 }
drhf9c8ce32013-11-05 13:33:55 +0000434 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000435 do_test func4-3.13 {
mistachkin32be00a2013-03-11 06:24:46 +0000436 catchsql {
437 INSERT INTO t1 (x) VALUES (X'');
438 }
drhf9c8ce32013-11-05 13:33:55 +0000439 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000440 do_test func4-3.14 {
mistachkin32be00a2013-03-11 06:24:46 +0000441 catchsql {
442 INSERT INTO t1 (x) VALUES (X'1234');
443 }
drhf9c8ce32013-11-05 13:33:55 +0000444 } {1 {CHECK constraint failed: t1}}
drh0057a742013-06-21 19:29:33 +0000445 do_test func4-3.15 {
mistachkin32be00a2013-03-11 06:24:46 +0000446 catchsql {
447 INSERT INTO t1 (x) VALUES (X'12345678');
448 }
drhf9c8ce32013-11-05 13:33:55 +0000449 } {1 {CHECK constraint failed: t1}}
mistachkin98ab33a2013-08-20 09:26:38 +0000450 do_test func4-3.16 {
451 catchsql {
452 INSERT INTO t1 (x) VALUES ('1234.00');
453 }
drhf9c8ce32013-11-05 13:33:55 +0000454 } {1 {CHECK constraint failed: t1}}
mistachkin98ab33a2013-08-20 09:26:38 +0000455 do_test func4-3.17 {
456 catchsql {
457 INSERT INTO t1 (x) VALUES (1234.00);
458 }
459 } {0 {}}
460 do_test func4-3.18 {
461 catchsql {
462 INSERT INTO t1 (x) VALUES ('-9223372036854775809');
463 }
drhf9c8ce32013-11-05 13:33:55 +0000464 } {1 {CHECK constraint failed: t1}}
mistachkinaeddf192013-09-04 00:58:00 +0000465 if {$highPrecision(1)} {
466 do_test func4-3.19 {
467 catchsql {
468 INSERT INTO t1 (x) VALUES (9223372036854775808);
469 }
drhf9c8ce32013-11-05 13:33:55 +0000470 } {1 {CHECK constraint failed: t1}}
mistachkinaeddf192013-09-04 00:58:00 +0000471 }
mistachkin98ab33a2013-08-20 09:26:38 +0000472 do_execsql_test func4-3.20 {
mistachkin32be00a2013-03-11 06:24:46 +0000473 SELECT x FROM t1 ORDER BY x;
mistachkin98ab33a2013-08-20 09:26:38 +0000474 } {1234 1234 1234}
mistachkinee1c64e2013-03-12 09:07:25 +0000475
476 ifcapable floatingpoint {
drh0057a742013-06-21 19:29:33 +0000477 do_execsql_test func4-4.1 {
mistachkinee1c64e2013-03-12 09:07:25 +0000478 CREATE TABLE t2(
mistachkinbc3ec282013-03-13 06:48:05 +0000479 x REAL CHECK(toreal(x) IS NOT NULL)
mistachkinee1c64e2013-03-12 09:07:25 +0000480 );
481 } {}
drh0057a742013-06-21 19:29:33 +0000482 do_test func4-4.2 {
mistachkinee1c64e2013-03-12 09:07:25 +0000483 catchsql {
484 INSERT INTO t2 (x) VALUES (NULL);
485 }
drhf9c8ce32013-11-05 13:33:55 +0000486 } {1 {CHECK constraint failed: t2}}
drh0057a742013-06-21 19:29:33 +0000487 do_test func4-4.3 {
mistachkinee1c64e2013-03-12 09:07:25 +0000488 catchsql {
489 INSERT INTO t2 (x) VALUES (NULL);
490 }
drhf9c8ce32013-11-05 13:33:55 +0000491 } {1 {CHECK constraint failed: t2}}
drh0057a742013-06-21 19:29:33 +0000492 do_test func4-4.4 {
mistachkinee1c64e2013-03-12 09:07:25 +0000493 catchsql {
494 INSERT INTO t2 (x) VALUES ('');
495 }
drhf9c8ce32013-11-05 13:33:55 +0000496 } {1 {CHECK constraint failed: t2}}
drh0057a742013-06-21 19:29:33 +0000497 do_test func4-4.5 {
mistachkinee1c64e2013-03-12 09:07:25 +0000498 catchsql {
499 INSERT INTO t2 (x) VALUES ('bad');
500 }
drhf9c8ce32013-11-05 13:33:55 +0000501 } {1 {CHECK constraint failed: t2}}
drh0057a742013-06-21 19:29:33 +0000502 do_test func4-4.6 {
mistachkinee1c64e2013-03-12 09:07:25 +0000503 catchsql {
504 INSERT INTO t2 (x) VALUES ('1234bad');
505 }
drhf9c8ce32013-11-05 13:33:55 +0000506 } {1 {CHECK constraint failed: t2}}
drh0057a742013-06-21 19:29:33 +0000507 do_test func4-4.7 {
mistachkinee1c64e2013-03-12 09:07:25 +0000508 catchsql {
509 INSERT INTO t2 (x) VALUES ('1234.56bad');
510 }
drhf9c8ce32013-11-05 13:33:55 +0000511 } {1 {CHECK constraint failed: t2}}
drh0057a742013-06-21 19:29:33 +0000512 do_test func4-4.8 {
mistachkinee1c64e2013-03-12 09:07:25 +0000513 catchsql {
514 INSERT INTO t2 (x) VALUES (1234);
515 }
516 } {0 {}}
drh0057a742013-06-21 19:29:33 +0000517 do_test func4-4.9 {
mistachkinee1c64e2013-03-12 09:07:25 +0000518 catchsql {
519 INSERT INTO t2 (x) VALUES (1234.56);
520 }
521 } {0 {}}
drh0057a742013-06-21 19:29:33 +0000522 do_test func4-4.10 {
mistachkinee1c64e2013-03-12 09:07:25 +0000523 catchsql {
524 INSERT INTO t2 (x) VALUES ('1234');
525 }
526 } {0 {}}
drh0057a742013-06-21 19:29:33 +0000527 do_test func4-4.11 {
mistachkinee1c64e2013-03-12 09:07:25 +0000528 catchsql {
529 INSERT INTO t2 (x) VALUES ('1234.56');
530 }
531 } {0 {}}
drh0057a742013-06-21 19:29:33 +0000532 do_test func4-4.12 {
mistachkinee1c64e2013-03-12 09:07:25 +0000533 catchsql {
534 INSERT INTO t2 (x) VALUES (ZEROBLOB(4));
535 }
drhf9c8ce32013-11-05 13:33:55 +0000536 } {1 {CHECK constraint failed: t2}}
drh0057a742013-06-21 19:29:33 +0000537 do_test func4-4.13 {
mistachkinee1c64e2013-03-12 09:07:25 +0000538 catchsql {
539 INSERT INTO t2 (x) VALUES (X'');
540 }
drhf9c8ce32013-11-05 13:33:55 +0000541 } {1 {CHECK constraint failed: t2}}
drh0057a742013-06-21 19:29:33 +0000542 do_test func4-4.14 {
mistachkinee1c64e2013-03-12 09:07:25 +0000543 catchsql {
544 INSERT INTO t2 (x) VALUES (X'1234');
545 }
drhf9c8ce32013-11-05 13:33:55 +0000546 } {1 {CHECK constraint failed: t2}}
drh0057a742013-06-21 19:29:33 +0000547 do_test func4-4.15 {
mistachkinee1c64e2013-03-12 09:07:25 +0000548 catchsql {
549 INSERT INTO t2 (x) VALUES (X'12345678');
550 }
drhf9c8ce32013-11-05 13:33:55 +0000551 } {1 {CHECK constraint failed: t2}}
drh0057a742013-06-21 19:29:33 +0000552 do_execsql_test func4-4.16 {
mistachkinee1c64e2013-03-12 09:07:25 +0000553 SELECT x FROM t2 ORDER BY x;
554 } {1234.0 1234.0 1234.56 1234.56}
555 }
mistachkin32be00a2013-03-11 06:24:46 +0000556}
557
mistachkin98ab33a2013-08-20 09:26:38 +0000558ifcapable floatingpoint {
559 do_execsql_test func4-5.1 {
560 SELECT tointeger(toreal('1234'));
561 } {1234}
562 do_execsql_test func4-5.2 {
563 SELECT tointeger(toreal(-1));
564 } {-1}
565 do_execsql_test func4-5.3 {
566 SELECT tointeger(toreal(-0));
567 } {0}
568 do_execsql_test func4-5.4 {
569 SELECT tointeger(toreal(0));
570 } {0}
571 do_execsql_test func4-5.5 {
572 SELECT tointeger(toreal(1));
573 } {1}
574 do_execsql_test func4-5.6 {
575 SELECT tointeger(toreal(-9223372036854775808 - 1));
576 } {-9223372036854775808}
577 do_execsql_test func4-5.7 {
578 SELECT tointeger(toreal(-9223372036854775808));
579 } {-9223372036854775808}
mistachkinaeddf192013-09-04 00:58:00 +0000580 if {$highPrecision(2)} {
mistachkina17713f2013-08-29 02:27:39 +0000581 do_execsql_test func4-5.8 {
582 SELECT tointeger(toreal(-9223372036854775808 + 1));
583 } {{}}
584 }
mistachkin98ab33a2013-08-20 09:26:38 +0000585 do_execsql_test func4-5.9 {
586 SELECT tointeger(toreal(-2147483648 - 1));
587 } {-2147483649}
588 do_execsql_test func4-5.10 {
589 SELECT tointeger(toreal(-2147483648));
590 } {-2147483648}
591 do_execsql_test func4-5.11 {
592 SELECT tointeger(toreal(-2147483648 + 1));
593 } {-2147483647}
594 do_execsql_test func4-5.12 {
595 SELECT tointeger(toreal(2147483647 - 1));
596 } {2147483646}
597 do_execsql_test func4-5.13 {
598 SELECT tointeger(toreal(2147483647));
599 } {2147483647}
600 do_execsql_test func4-5.14 {
601 SELECT tointeger(toreal(2147483647 + 1));
602 } {2147483648}
603 do_execsql_test func4-5.15 {
604 SELECT tointeger(toreal(9223372036854775807 - 1));
605 } {{}}
mistachkinaeddf192013-09-04 00:58:00 +0000606 if {$highPrecision(1)} {
607 do_execsql_test func4-5.16 {
608 SELECT tointeger(toreal(9223372036854775807));
609 } {{}}
610 do_execsql_test func4-5.17 {
611 SELECT tointeger(toreal(9223372036854775807 + 1));
612 } {{}}
613 }
mistachkin98ab33a2013-08-20 09:26:38 +0000614 do_execsql_test func4-5.18 {
615 SELECT tointeger(toreal(4503599627370496 - 1));
616 } {4503599627370495}
617 do_execsql_test func4-5.19 {
618 SELECT tointeger(toreal(4503599627370496));
619 } {4503599627370496}
620 do_execsql_test func4-5.20 {
621 SELECT tointeger(toreal(4503599627370496 + 1));
622 } {4503599627370497}
623 do_execsql_test func4-5.21 {
624 SELECT tointeger(toreal(9007199254740992 - 1));
625 } {9007199254740991}
626 do_execsql_test func4-5.22 {
627 SELECT tointeger(toreal(9007199254740992));
628 } {9007199254740992}
mistachkinaeddf192013-09-04 00:58:00 +0000629 if {$highPrecision(2)} {
mistachkina17713f2013-08-29 02:27:39 +0000630 do_execsql_test func4-5.23 {
631 SELECT tointeger(toreal(9007199254740992 + 1));
632 } {{}}
633 }
mistachkin98ab33a2013-08-20 09:26:38 +0000634 do_execsql_test func4-5.24 {
635 SELECT tointeger(toreal(9007199254740992 + 2));
636 } {9007199254740994}
mistachkinaeddf192013-09-04 00:58:00 +0000637 if {$highPrecision(1)} {
638 do_execsql_test func4-5.25 {
639 SELECT tointeger(toreal(9223372036854775808 - 1));
640 } {{}}
641 do_execsql_test func4-5.26 {
642 SELECT tointeger(toreal(9223372036854775808));
643 } {{}}
644 do_execsql_test func4-5.27 {
645 SELECT tointeger(toreal(9223372036854775808 + 1));
646 } {{}}
647 }
mistachkin98ab33a2013-08-20 09:26:38 +0000648 do_execsql_test func4-5.28 {
649 SELECT tointeger(toreal(18446744073709551616 - 1));
650 } {{}}
651 do_execsql_test func4-5.29 {
652 SELECT tointeger(toreal(18446744073709551616));
653 } {{}}
654 do_execsql_test func4-5.30 {
655 SELECT tointeger(toreal(18446744073709551616 + 1));
656 } {{}}
657}
658
mistachkinaeddf192013-09-04 00:58:00 +0000659for {set i 0} {$i < 10} {incr i} {
660 if {$i == 8} continue
661 do_execsql_test func4-6.1.$i.1 [subst {
662 SELECT tointeger(x'[string repeat 01 $i]');
663 }] {{}}
664 ifcapable floatingpoint {
665 do_execsql_test func4-6.1.$i.2 [subst {
666 SELECT toreal(x'[string repeat 01 $i]');
667 }] {{}}
668 }
669}
670
mistachkin9a5b2712013-09-06 20:30:53 +0000671do_execsql_test func4-6.2.1 {
672 SELECT tointeger(x'0102030405060708');
673} {578437695752307201}
674do_execsql_test func4-6.2.2 {
675 SELECT tointeger(x'0807060504030201');
676} {72623859790382856}
mistachkinaeddf192013-09-04 00:58:00 +0000677
678ifcapable floatingpoint {
mistachkin9a5b2712013-09-06 20:30:53 +0000679 do_execsql_test func4-6.3.1 {
680 SELECT toreal(x'ffefffffffffffff');
681 } {-1.7976931348623157e+308}
682 do_execsql_test func4-6.3.2 {
683 SELECT toreal(x'8010000000000000');
684 } {-2.2250738585072014e-308}
685 do_execsql_test func4-6.3.3 {
686 SELECT toreal(x'c000000000000000');
687 } {-2.0}
688 do_execsql_test func4-6.3.4 {
689 SELECT toreal(x'bff0000000000000');
690 } {-1.0}
691 do_execsql_test func4-6.3.5 {
692 SELECT toreal(x'8000000000000000');
693 } {-0.0}
694 do_execsql_test func4-6.3.6 {
695 SELECT toreal(x'0000000000000000');
696 } {0.0}
697 do_execsql_test func4-6.3.7 {
698 SELECT toreal(x'3ff0000000000000');
699 } {1.0}
700 do_execsql_test func4-6.3.8 {
701 SELECT toreal(x'4000000000000000');
702 } {2.0}
703 do_execsql_test func4-6.3.9 {
704 SELECT toreal(x'0010000000000000');
705 } {2.2250738585072014e-308}
706 do_execsql_test func4-6.3.10 {
707 SELECT toreal(x'7fefffffffffffff');
708 } {1.7976931348623157e+308}
709 do_execsql_test func4-6.3.11 {
710 SELECT toreal(x'8000000000000001');
711 } {-5e-324}
712 do_execsql_test func4-6.3.12 {
713 SELECT toreal(x'800fffffffffffff');
714 } {-2.225073858507201e-308}
715 do_execsql_test func4-6.3.13 {
716 SELECT toreal(x'0000000000000001');
717 } {5e-324}
718 do_execsql_test func4-6.3.14 {
719 SELECT toreal(x'000fffffffffffff');
720 } {2.225073858507201e-308}
721 do_execsql_test func4-6.3.15 {
722 SELECT toreal(x'fff0000000000000');
723 } {-Inf}
724 do_execsql_test func4-6.3.16 {
725 SELECT toreal(x'7ff0000000000000');
726 } {Inf}
727 do_execsql_test func4-6.3.17 {
728 SELECT toreal(x'fff8000000000000');
729 } {{}}
730 do_execsql_test func4-6.3.18 {
731 SELECT toreal(x'fff0000000000001');
732 } {{}}
733 do_execsql_test func4-6.3.19 {
734 SELECT toreal(x'fff7ffffffffffff');
735 } {{}}
736 do_execsql_test func4-6.3.20 {
737 SELECT toreal(x'7ff0000000000001');
738 } {{}}
739 do_execsql_test func4-6.3.21 {
740 SELECT toreal(x'7ff7ffffffffffff');
741 } {{}}
742 do_execsql_test func4-6.3.22 {
743 SELECT toreal(x'fff8000000000001');
744 } {{}}
745 do_execsql_test func4-6.3.23 {
746 SELECT toreal(x'ffffffffffffffff');
747 } {{}}
748 do_execsql_test func4-6.3.24 {
749 SELECT toreal(x'7ff8000000000000');
750 } {{}}
751 do_execsql_test func4-6.3.25 {
752 SELECT toreal(x'7fffffffffffffff');
753 } {{}}
mistachkinaeddf192013-09-04 00:58:00 +0000754}
755
mistachkin98ab33a2013-08-20 09:26:38 +0000756set tcl_precision $saved_tcl_precision
757unset saved_tcl_precision
mistachkin69f3d042013-03-11 01:23:37 +0000758finish_test