1
0

func4.test 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. # 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. #***********************************************************************
  11. # 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.
  17. #
  18. set testdir [file dirname $argv0]
  19. source $testdir/tester.tcl
  20. set saved_tcl_precision $tcl_precision
  21. set tcl_precision 0
  22. load_static_extension db totype
  23. set highPrecision(1) [expr \
  24. {[db eval {SELECT tointeger(9223372036854775807 + 1);}] eq {{}}}]
  25. do_execsql_test func4-1.1 {
  26. SELECT tointeger(NULL);
  27. } {{}}
  28. do_execsql_test func4-1.2 {
  29. SELECT tointeger('');
  30. } {{}}
  31. do_execsql_test func4-1.3 {
  32. SELECT tointeger(' ');
  33. } {{}}
  34. do_execsql_test func4-1.4 {
  35. SELECT tointeger('1234');
  36. } {1234}
  37. do_execsql_test func4-1.5 {
  38. SELECT tointeger(' 1234');
  39. } {{}}
  40. do_execsql_test func4-1.6 {
  41. SELECT tointeger('bad');
  42. } {{}}
  43. do_execsql_test func4-1.7 {
  44. SELECT tointeger('0xBAD');
  45. } {{}}
  46. do_execsql_test func4-1.8 {
  47. SELECT tointeger('123BAD');
  48. } {{}}
  49. do_execsql_test func4-1.9 {
  50. SELECT tointeger('0x123BAD');
  51. } {{}}
  52. do_execsql_test func4-1.10 {
  53. SELECT tointeger('123NO');
  54. } {{}}
  55. do_execsql_test func4-1.11 {
  56. SELECT tointeger('0x123NO');
  57. } {{}}
  58. do_execsql_test func4-1.12 {
  59. SELECT tointeger('-0x1');
  60. } {{}}
  61. do_execsql_test func4-1.13 {
  62. SELECT tointeger('-0x0');
  63. } {{}}
  64. do_execsql_test func4-1.14 {
  65. SELECT tointeger('0x0');
  66. } {{}}
  67. do_execsql_test func4-1.15 {
  68. SELECT tointeger('0x1');
  69. } {{}}
  70. do_execsql_test func4-1.16 {
  71. SELECT tointeger(-1);
  72. } {-1}
  73. do_execsql_test func4-1.17 {
  74. SELECT tointeger(-0);
  75. } {0}
  76. do_execsql_test func4-1.18 {
  77. SELECT tointeger(0);
  78. } {0}
  79. do_execsql_test func4-1.19 {
  80. SELECT tointeger(1);
  81. } {1}
  82. do_execsql_test func4-1.20 {
  83. SELECT tointeger(-1.79769313486232e308 - 1);
  84. } {{}}
  85. do_execsql_test func4-1.21 {
  86. SELECT tointeger(-1.79769313486232e308);
  87. } {{}}
  88. do_execsql_test func4-1.22 {
  89. SELECT tointeger(-1.79769313486232e308 + 1);
  90. } {{}}
  91. do_execsql_test func4-1.23 {
  92. SELECT tointeger(-9223372036854775808 - 1);
  93. } {-9223372036854775808}
  94. do_execsql_test func4-1.24 {
  95. SELECT tointeger(-9223372036854775808);
  96. } {-9223372036854775808}
  97. do_execsql_test func4-1.25 {
  98. SELECT tointeger(-9223372036854775808 + 1);
  99. } {-9223372036854775807}
  100. do_execsql_test func4-1.26 {
  101. SELECT tointeger(-9223372036854775807 - 1);
  102. } {-9223372036854775808}
  103. do_execsql_test func4-1.27 {
  104. SELECT tointeger(-9223372036854775807);
  105. } {-9223372036854775807}
  106. do_execsql_test func4-1.28 {
  107. SELECT tointeger(-9223372036854775807 + 1);
  108. } {-9223372036854775806}
  109. do_execsql_test func4-1.29 {
  110. SELECT tointeger(-2147483648 - 1);
  111. } {-2147483649}
  112. do_execsql_test func4-1.30 {
  113. SELECT tointeger(-2147483648);
  114. } {-2147483648}
  115. do_execsql_test func4-1.31 {
  116. SELECT tointeger(-2147483648 + 1);
  117. } {-2147483647}
  118. do_execsql_test func4-1.32 {
  119. SELECT tointeger(2147483647 - 1);
  120. } {2147483646}
  121. do_execsql_test func4-1.33 {
  122. SELECT tointeger(2147483647);
  123. } {2147483647}
  124. do_execsql_test func4-1.34 {
  125. SELECT tointeger(2147483647 + 1);
  126. } {2147483648}
  127. do_execsql_test func4-1.35 {
  128. SELECT tointeger(9223372036854775807 - 1);
  129. } {9223372036854775806}
  130. do_execsql_test func4-1.36 {
  131. SELECT tointeger(9223372036854775807);
  132. } {9223372036854775807}
  133. if {$highPrecision(1)} {
  134. do_execsql_test func4-1.37 {
  135. SELECT tointeger(9223372036854775807 + 1);
  136. } {{}}
  137. }
  138. do_execsql_test func4-1.38 {
  139. SELECT tointeger(1.79769313486232e308 - 1);
  140. } {{}}
  141. do_execsql_test func4-1.39 {
  142. SELECT tointeger(1.79769313486232e308);
  143. } {{}}
  144. do_execsql_test func4-1.40 {
  145. SELECT tointeger(1.79769313486232e308 + 1);
  146. } {{}}
  147. do_execsql_test func4-1.41 {
  148. SELECT tointeger(4503599627370496 - 1);
  149. } {4503599627370495}
  150. do_execsql_test func4-1.42 {
  151. SELECT tointeger(4503599627370496);
  152. } {4503599627370496}
  153. do_execsql_test func4-1.43 {
  154. SELECT tointeger(4503599627370496 + 1);
  155. } {4503599627370497}
  156. do_execsql_test func4-1.44 {
  157. SELECT tointeger(9007199254740992 - 1);
  158. } {9007199254740991}
  159. do_execsql_test func4-1.45 {
  160. SELECT tointeger(9007199254740992);
  161. } {9007199254740992}
  162. do_execsql_test func4-1.46 {
  163. SELECT tointeger(9007199254740992 + 1);
  164. } {9007199254740993}
  165. do_execsql_test func4-1.47 {
  166. SELECT tointeger(9223372036854775807 - 1);
  167. } {9223372036854775806}
  168. do_execsql_test func4-1.48 {
  169. SELECT tointeger(9223372036854775807);
  170. } {9223372036854775807}
  171. if {$highPrecision(1)} {
  172. do_execsql_test func4-1.49 {
  173. SELECT tointeger(9223372036854775807 + 1);
  174. } {{}}
  175. do_execsql_test func4-1.50 {
  176. SELECT tointeger(9223372036854775808 - 1);
  177. } {{}}
  178. do_execsql_test func4-1.51 {
  179. SELECT tointeger(9223372036854775808);
  180. } {{}}
  181. do_execsql_test func4-1.52 {
  182. SELECT tointeger(9223372036854775808 + 1);
  183. } {{}}
  184. }
  185. do_execsql_test func4-1.53 {
  186. SELECT tointeger(18446744073709551616 - 1);
  187. } {{}}
  188. do_execsql_test func4-1.54 {
  189. SELECT tointeger(18446744073709551616);
  190. } {{}}
  191. do_execsql_test func4-1.55 {
  192. SELECT tointeger(18446744073709551616 + 1);
  193. } {{}}
  194. ifcapable floatingpoint {
  195. set highPrecision(2) [expr \
  196. {[db eval {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}]
  197. do_execsql_test func4-2.1 {
  198. SELECT toreal(NULL);
  199. } {{}}
  200. do_execsql_test func4-2.2 {
  201. SELECT toreal('');
  202. } {{}}
  203. do_execsql_test func4-2.3 {
  204. SELECT toreal(' ');
  205. } {{}}
  206. do_execsql_test func4-2.4 {
  207. SELECT toreal('1234');
  208. } {1234.0}
  209. do_execsql_test func4-2.5 {
  210. SELECT toreal(' 1234');
  211. } {{}}
  212. do_execsql_test func4-2.6 {
  213. SELECT toreal('bad');
  214. } {{}}
  215. do_execsql_test func4-2.7 {
  216. SELECT toreal('0xBAD');
  217. } {{}}
  218. do_execsql_test func4-2.8 {
  219. SELECT toreal('123BAD');
  220. } {{}}
  221. do_execsql_test func4-2.9 {
  222. SELECT toreal('0x123BAD');
  223. } {{}}
  224. do_execsql_test func4-2.10 {
  225. SELECT toreal('123NO');
  226. } {{}}
  227. do_execsql_test func4-2.11 {
  228. SELECT toreal('0x123NO');
  229. } {{}}
  230. do_execsql_test func4-2.12 {
  231. SELECT toreal('-0x1');
  232. } {{}}
  233. do_execsql_test func4-2.13 {
  234. SELECT toreal('-0x0');
  235. } {{}}
  236. do_execsql_test func4-2.14 {
  237. SELECT toreal('0x0');
  238. } {{}}
  239. do_execsql_test func4-2.15 {
  240. SELECT toreal('0x1');
  241. } {{}}
  242. do_execsql_test func4-2.16 {
  243. SELECT toreal(-1);
  244. } {-1.0}
  245. do_execsql_test func4-2.17 {
  246. SELECT toreal(-0);
  247. } {0.0}
  248. do_execsql_test func4-2.18 {
  249. SELECT toreal(0);
  250. } {0.0}
  251. do_execsql_test func4-2.19 {
  252. SELECT toreal(1);
  253. } {1.0}
  254. do_execsql_test func4-2.20 {
  255. SELECT toreal(-1.79769313486232e308 - 1);
  256. } {-Inf}
  257. do_execsql_test func4-2.21 {
  258. SELECT toreal(-1.79769313486232e308);
  259. } {-Inf}
  260. do_execsql_test func4-2.22 {
  261. SELECT toreal(-1.79769313486232e308 + 1);
  262. } {-Inf}
  263. do_execsql_test func4-2.23 {
  264. SELECT toreal(-9223372036854775808 - 1);
  265. } {-9.223372036854776e+18}
  266. do_execsql_test func4-2.24 {
  267. SELECT toreal(-9223372036854775808);
  268. } {-9.223372036854776e+18}
  269. if {$highPrecision(2)} {
  270. do_execsql_test func4-2.25 {
  271. SELECT toreal(-9223372036854775808 + 1);
  272. } {{}}
  273. }
  274. do_execsql_test func4-2.26 {
  275. SELECT toreal(-9223372036854775807 - 1);
  276. } {-9.223372036854776e+18}
  277. if {$highPrecision(2)} {
  278. do_execsql_test func4-2.27 {
  279. SELECT toreal(-9223372036854775807);
  280. } {{}}
  281. do_execsql_test func4-2.28 {
  282. SELECT toreal(-9223372036854775807 + 1);
  283. } {{}}
  284. }
  285. do_execsql_test func4-2.29 {
  286. SELECT toreal(-2147483648 - 1);
  287. } {-2147483649.0}
  288. do_execsql_test func4-2.30 {
  289. SELECT toreal(-2147483648);
  290. } {-2147483648.0}
  291. do_execsql_test func4-2.31 {
  292. SELECT toreal(-2147483648 + 1);
  293. } {-2147483647.0}
  294. do_execsql_test func4-2.32 {
  295. SELECT toreal(2147483647 - 1);
  296. } {2147483646.0}
  297. do_execsql_test func4-2.33 {
  298. SELECT toreal(2147483647);
  299. } {2147483647.0}
  300. do_execsql_test func4-2.34 {
  301. SELECT toreal(2147483647 + 1);
  302. } {2147483648.0}
  303. if {$highPrecision(2)} {
  304. do_execsql_test func4-2.35 {
  305. SELECT toreal(9223372036854775807 - 1);
  306. } {{}}
  307. if {$highPrecision(1)} {
  308. do_execsql_test func4-2.36 {
  309. SELECT toreal(9223372036854775807);
  310. } {{}}
  311. }
  312. }
  313. do_execsql_test func4-2.37 {
  314. SELECT toreal(9223372036854775807 + 1);
  315. } {9.223372036854776e+18}
  316. do_execsql_test func4-2.38 {
  317. SELECT toreal(1.79769313486232e308 - 1);
  318. } {Inf}
  319. do_execsql_test func4-2.39 {
  320. SELECT toreal(1.79769313486232e308);
  321. } {Inf}
  322. do_execsql_test func4-2.40 {
  323. SELECT toreal(1.79769313486232e308 + 1);
  324. } {Inf}
  325. do_execsql_test func4-2.41 {
  326. SELECT toreal(4503599627370496 - 1);
  327. } {4503599627370495.0}
  328. do_execsql_test func4-2.42 {
  329. SELECT toreal(4503599627370496);
  330. } {4503599627370496.0}
  331. do_execsql_test func4-2.43 {
  332. SELECT toreal(4503599627370496 + 1);
  333. } {4503599627370497.0}
  334. do_execsql_test func4-2.44 {
  335. SELECT toreal(9007199254740992 - 1);
  336. } {9007199254740991.0}
  337. do_execsql_test func4-2.45 {
  338. SELECT toreal(9007199254740992);
  339. } {9007199254740992.0}
  340. if {$highPrecision(2)} {
  341. do_execsql_test func4-2.46 {
  342. SELECT toreal(9007199254740992 + 1);
  343. } {{}}
  344. }
  345. do_execsql_test func4-2.47 {
  346. SELECT toreal(9007199254740992 + 2);
  347. } {9007199254740994.0}
  348. do_execsql_test func4-2.48 {
  349. SELECT toreal(tointeger(9223372036854775808) - 1);
  350. } {{}}
  351. if {$highPrecision(1)} {
  352. do_execsql_test func4-2.49 {
  353. SELECT toreal(tointeger(9223372036854775808));
  354. } {{}}
  355. do_execsql_test func4-2.50 {
  356. SELECT toreal(tointeger(9223372036854775808) + 1);
  357. } {{}}
  358. }
  359. do_execsql_test func4-2.51 {
  360. SELECT toreal(tointeger(18446744073709551616) - 1);
  361. } {{}}
  362. do_execsql_test func4-2.52 {
  363. SELECT toreal(tointeger(18446744073709551616));
  364. } {{}}
  365. do_execsql_test func4-2.53 {
  366. SELECT toreal(tointeger(18446744073709551616) + 1);
  367. } {{}}
  368. }
  369. ifcapable check {
  370. do_execsql_test func4-3.1 {
  371. CREATE TABLE t1(
  372. x INTEGER CHECK(tointeger(x) IS NOT NULL)
  373. );
  374. } {}
  375. do_test func4-3.2 {
  376. catchsql {
  377. INSERT INTO t1 (x) VALUES (NULL);
  378. }
  379. } {1 {constraint failed}}
  380. do_test func4-3.3 {
  381. catchsql {
  382. INSERT INTO t1 (x) VALUES (NULL);
  383. }
  384. } {1 {constraint failed}}
  385. do_test func4-3.4 {
  386. catchsql {
  387. INSERT INTO t1 (x) VALUES ('');
  388. }
  389. } {1 {constraint failed}}
  390. do_test func4-3.5 {
  391. catchsql {
  392. INSERT INTO t1 (x) VALUES ('bad');
  393. }
  394. } {1 {constraint failed}}
  395. do_test func4-3.6 {
  396. catchsql {
  397. INSERT INTO t1 (x) VALUES ('1234bad');
  398. }
  399. } {1 {constraint failed}}
  400. do_test func4-3.7 {
  401. catchsql {
  402. INSERT INTO t1 (x) VALUES ('1234.56bad');
  403. }
  404. } {1 {constraint failed}}
  405. do_test func4-3.8 {
  406. catchsql {
  407. INSERT INTO t1 (x) VALUES (1234);
  408. }
  409. } {0 {}}
  410. do_test func4-3.9 {
  411. catchsql {
  412. INSERT INTO t1 (x) VALUES (1234.56);
  413. }
  414. } {1 {constraint failed}}
  415. do_test func4-3.10 {
  416. catchsql {
  417. INSERT INTO t1 (x) VALUES ('1234');
  418. }
  419. } {0 {}}
  420. do_test func4-3.11 {
  421. catchsql {
  422. INSERT INTO t1 (x) VALUES ('1234.56');
  423. }
  424. } {1 {constraint failed}}
  425. do_test func4-3.12 {
  426. catchsql {
  427. INSERT INTO t1 (x) VALUES (ZEROBLOB(4));
  428. }
  429. } {1 {constraint failed}}
  430. do_test func4-3.13 {
  431. catchsql {
  432. INSERT INTO t1 (x) VALUES (X'');
  433. }
  434. } {1 {constraint failed}}
  435. do_test func4-3.14 {
  436. catchsql {
  437. INSERT INTO t1 (x) VALUES (X'1234');
  438. }
  439. } {1 {constraint failed}}
  440. do_test func4-3.15 {
  441. catchsql {
  442. INSERT INTO t1 (x) VALUES (X'12345678');
  443. }
  444. } {1 {constraint failed}}
  445. do_test func4-3.16 {
  446. catchsql {
  447. INSERT INTO t1 (x) VALUES ('1234.00');
  448. }
  449. } {1 {constraint failed}}
  450. do_test func4-3.17 {
  451. catchsql {
  452. INSERT INTO t1 (x) VALUES (1234.00);
  453. }
  454. } {0 {}}
  455. do_test func4-3.18 {
  456. catchsql {
  457. INSERT INTO t1 (x) VALUES ('-9223372036854775809');
  458. }
  459. } {1 {constraint failed}}
  460. if {$highPrecision(1)} {
  461. do_test func4-3.19 {
  462. catchsql {
  463. INSERT INTO t1 (x) VALUES (9223372036854775808);
  464. }
  465. } {1 {constraint failed}}
  466. }
  467. do_execsql_test func4-3.20 {
  468. SELECT x FROM t1 ORDER BY x;
  469. } {1234 1234 1234}
  470. ifcapable floatingpoint {
  471. do_execsql_test func4-4.1 {
  472. CREATE TABLE t2(
  473. x REAL CHECK(toreal(x) IS NOT NULL)
  474. );
  475. } {}
  476. do_test func4-4.2 {
  477. catchsql {
  478. INSERT INTO t2 (x) VALUES (NULL);
  479. }
  480. } {1 {constraint failed}}
  481. do_test func4-4.3 {
  482. catchsql {
  483. INSERT INTO t2 (x) VALUES (NULL);
  484. }
  485. } {1 {constraint failed}}
  486. do_test func4-4.4 {
  487. catchsql {
  488. INSERT INTO t2 (x) VALUES ('');
  489. }
  490. } {1 {constraint failed}}
  491. do_test func4-4.5 {
  492. catchsql {
  493. INSERT INTO t2 (x) VALUES ('bad');
  494. }
  495. } {1 {constraint failed}}
  496. do_test func4-4.6 {
  497. catchsql {
  498. INSERT INTO t2 (x) VALUES ('1234bad');
  499. }
  500. } {1 {constraint failed}}
  501. do_test func4-4.7 {
  502. catchsql {
  503. INSERT INTO t2 (x) VALUES ('1234.56bad');
  504. }
  505. } {1 {constraint failed}}
  506. do_test func4-4.8 {
  507. catchsql {
  508. INSERT INTO t2 (x) VALUES (1234);
  509. }
  510. } {0 {}}
  511. do_test func4-4.9 {
  512. catchsql {
  513. INSERT INTO t2 (x) VALUES (1234.56);
  514. }
  515. } {0 {}}
  516. do_test func4-4.10 {
  517. catchsql {
  518. INSERT INTO t2 (x) VALUES ('1234');
  519. }
  520. } {0 {}}
  521. do_test func4-4.11 {
  522. catchsql {
  523. INSERT INTO t2 (x) VALUES ('1234.56');
  524. }
  525. } {0 {}}
  526. do_test func4-4.12 {
  527. catchsql {
  528. INSERT INTO t2 (x) VALUES (ZEROBLOB(4));
  529. }
  530. } {1 {constraint failed}}
  531. do_test func4-4.13 {
  532. catchsql {
  533. INSERT INTO t2 (x) VALUES (X'');
  534. }
  535. } {1 {constraint failed}}
  536. do_test func4-4.14 {
  537. catchsql {
  538. INSERT INTO t2 (x) VALUES (X'1234');
  539. }
  540. } {1 {constraint failed}}
  541. do_test func4-4.15 {
  542. catchsql {
  543. INSERT INTO t2 (x) VALUES (X'12345678');
  544. }
  545. } {1 {constraint failed}}
  546. do_execsql_test func4-4.16 {
  547. SELECT x FROM t2 ORDER BY x;
  548. } {1234.0 1234.0 1234.56 1234.56}
  549. }
  550. }
  551. ifcapable floatingpoint {
  552. do_execsql_test func4-5.1 {
  553. SELECT tointeger(toreal('1234'));
  554. } {1234}
  555. do_execsql_test func4-5.2 {
  556. SELECT tointeger(toreal(-1));
  557. } {-1}
  558. do_execsql_test func4-5.3 {
  559. SELECT tointeger(toreal(-0));
  560. } {0}
  561. do_execsql_test func4-5.4 {
  562. SELECT tointeger(toreal(0));
  563. } {0}
  564. do_execsql_test func4-5.5 {
  565. SELECT tointeger(toreal(1));
  566. } {1}
  567. do_execsql_test func4-5.6 {
  568. SELECT tointeger(toreal(-9223372036854775808 - 1));
  569. } {-9223372036854775808}
  570. do_execsql_test func4-5.7 {
  571. SELECT tointeger(toreal(-9223372036854775808));
  572. } {-9223372036854775808}
  573. if {$highPrecision(2)} {
  574. do_execsql_test func4-5.8 {
  575. SELECT tointeger(toreal(-9223372036854775808 + 1));
  576. } {{}}
  577. }
  578. do_execsql_test func4-5.9 {
  579. SELECT tointeger(toreal(-2147483648 - 1));
  580. } {-2147483649}
  581. do_execsql_test func4-5.10 {
  582. SELECT tointeger(toreal(-2147483648));
  583. } {-2147483648}
  584. do_execsql_test func4-5.11 {
  585. SELECT tointeger(toreal(-2147483648 + 1));
  586. } {-2147483647}
  587. do_execsql_test func4-5.12 {
  588. SELECT tointeger(toreal(2147483647 - 1));
  589. } {2147483646}
  590. do_execsql_test func4-5.13 {
  591. SELECT tointeger(toreal(2147483647));
  592. } {2147483647}
  593. do_execsql_test func4-5.14 {
  594. SELECT tointeger(toreal(2147483647 + 1));
  595. } {2147483648}
  596. do_execsql_test func4-5.15 {
  597. SELECT tointeger(toreal(9223372036854775807 - 1));
  598. } {{}}
  599. if {$highPrecision(1)} {
  600. do_execsql_test func4-5.16 {
  601. SELECT tointeger(toreal(9223372036854775807));
  602. } {{}}
  603. do_execsql_test func4-5.17 {
  604. SELECT tointeger(toreal(9223372036854775807 + 1));
  605. } {{}}
  606. }
  607. do_execsql_test func4-5.18 {
  608. SELECT tointeger(toreal(4503599627370496 - 1));
  609. } {4503599627370495}
  610. do_execsql_test func4-5.19 {
  611. SELECT tointeger(toreal(4503599627370496));
  612. } {4503599627370496}
  613. do_execsql_test func4-5.20 {
  614. SELECT tointeger(toreal(4503599627370496 + 1));
  615. } {4503599627370497}
  616. do_execsql_test func4-5.21 {
  617. SELECT tointeger(toreal(9007199254740992 - 1));
  618. } {9007199254740991}
  619. do_execsql_test func4-5.22 {
  620. SELECT tointeger(toreal(9007199254740992));
  621. } {9007199254740992}
  622. if {$highPrecision(2)} {
  623. do_execsql_test func4-5.23 {
  624. SELECT tointeger(toreal(9007199254740992 + 1));
  625. } {{}}
  626. }
  627. do_execsql_test func4-5.24 {
  628. SELECT tointeger(toreal(9007199254740992 + 2));
  629. } {9007199254740994}
  630. if {$highPrecision(1)} {
  631. do_execsql_test func4-5.25 {
  632. SELECT tointeger(toreal(9223372036854775808 - 1));
  633. } {{}}
  634. do_execsql_test func4-5.26 {
  635. SELECT tointeger(toreal(9223372036854775808));
  636. } {{}}
  637. do_execsql_test func4-5.27 {
  638. SELECT tointeger(toreal(9223372036854775808 + 1));
  639. } {{}}
  640. }
  641. do_execsql_test func4-5.28 {
  642. SELECT tointeger(toreal(18446744073709551616 - 1));
  643. } {{}}
  644. do_execsql_test func4-5.29 {
  645. SELECT tointeger(toreal(18446744073709551616));
  646. } {{}}
  647. do_execsql_test func4-5.30 {
  648. SELECT tointeger(toreal(18446744073709551616 + 1));
  649. } {{}}
  650. }
  651. for {set i 0} {$i < 10} {incr i} {
  652. if {$i == 8} continue
  653. do_execsql_test func4-6.1.$i.1 [subst {
  654. SELECT tointeger(x'[string repeat 01 $i]');
  655. }] {{}}
  656. ifcapable floatingpoint {
  657. do_execsql_test func4-6.1.$i.2 [subst {
  658. SELECT toreal(x'[string repeat 01 $i]');
  659. }] {{}}
  660. }
  661. }
  662. do_execsql_test func4-6.2.1 {
  663. SELECT tointeger(x'0102030405060708');
  664. } {578437695752307201}
  665. do_execsql_test func4-6.2.2 {
  666. SELECT tointeger(x'0807060504030201');
  667. } {72623859790382856}
  668. ifcapable floatingpoint {
  669. do_execsql_test func4-6.3.1 {
  670. SELECT toreal(x'ffefffffffffffff');
  671. } {-1.7976931348623157e+308}
  672. do_execsql_test func4-6.3.2 {
  673. SELECT toreal(x'8010000000000000');
  674. } {-2.2250738585072014e-308}
  675. do_execsql_test func4-6.3.3 {
  676. SELECT toreal(x'c000000000000000');
  677. } {-2.0}
  678. do_execsql_test func4-6.3.4 {
  679. SELECT toreal(x'bff0000000000000');
  680. } {-1.0}
  681. do_execsql_test func4-6.3.5 {
  682. SELECT toreal(x'8000000000000000');
  683. } {-0.0}
  684. do_execsql_test func4-6.3.6 {
  685. SELECT toreal(x'0000000000000000');
  686. } {0.0}
  687. do_execsql_test func4-6.3.7 {
  688. SELECT toreal(x'3ff0000000000000');
  689. } {1.0}
  690. do_execsql_test func4-6.3.8 {
  691. SELECT toreal(x'4000000000000000');
  692. } {2.0}
  693. do_execsql_test func4-6.3.9 {
  694. SELECT toreal(x'0010000000000000');
  695. } {2.2250738585072014e-308}
  696. do_execsql_test func4-6.3.10 {
  697. SELECT toreal(x'7fefffffffffffff');
  698. } {1.7976931348623157e+308}
  699. do_execsql_test func4-6.3.11 {
  700. SELECT toreal(x'8000000000000001');
  701. } {-5e-324}
  702. do_execsql_test func4-6.3.12 {
  703. SELECT toreal(x'800fffffffffffff');
  704. } {-2.225073858507201e-308}
  705. do_execsql_test func4-6.3.13 {
  706. SELECT toreal(x'0000000000000001');
  707. } {5e-324}
  708. do_execsql_test func4-6.3.14 {
  709. SELECT toreal(x'000fffffffffffff');
  710. } {2.225073858507201e-308}
  711. do_execsql_test func4-6.3.15 {
  712. SELECT toreal(x'fff0000000000000');
  713. } {-Inf}
  714. do_execsql_test func4-6.3.16 {
  715. SELECT toreal(x'7ff0000000000000');
  716. } {Inf}
  717. do_execsql_test func4-6.3.17 {
  718. SELECT toreal(x'fff8000000000000');
  719. } {{}}
  720. do_execsql_test func4-6.3.18 {
  721. SELECT toreal(x'fff0000000000001');
  722. } {{}}
  723. do_execsql_test func4-6.3.19 {
  724. SELECT toreal(x'fff7ffffffffffff');
  725. } {{}}
  726. do_execsql_test func4-6.3.20 {
  727. SELECT toreal(x'7ff0000000000001');
  728. } {{}}
  729. do_execsql_test func4-6.3.21 {
  730. SELECT toreal(x'7ff7ffffffffffff');
  731. } {{}}
  732. do_execsql_test func4-6.3.22 {
  733. SELECT toreal(x'fff8000000000001');
  734. } {{}}
  735. do_execsql_test func4-6.3.23 {
  736. SELECT toreal(x'ffffffffffffffff');
  737. } {{}}
  738. do_execsql_test func4-6.3.24 {
  739. SELECT toreal(x'7ff8000000000000');
  740. } {{}}
  741. do_execsql_test func4-6.3.25 {
  742. SELECT toreal(x'7fffffffffffffff');
  743. } {{}}
  744. }
  745. set tcl_precision $saved_tcl_precision
  746. unset saved_tcl_precision
  747. finish_test