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