atof1.test 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # 2012 June 18
  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. #
  12. # Tests of the sqlite3AtoF() function.
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. if {![info exists __GNUC__]} {
  17. finish_test
  18. return
  19. }
  20. expr srand(1)
  21. for {set i 1} {$i<20000} {incr i} {
  22. set pow [expr {int((rand()-0.5)*100)}]
  23. set x [expr {pow((rand()-0.5)*2*rand(),$pow)}]
  24. set xf [format %.32e $x]
  25. # Verify that text->real conversions get exactly same ieee754 floating-
  26. # point value in SQLite as they do in TCL.
  27. #
  28. do_test atof1-1.$i.1 {
  29. set y [db eval "SELECT $xf=\$x"]
  30. if {!$y} {
  31. puts -nonewline \173[db eval "SELECT real2hex($xf), real2hex(\$x)"]\175
  32. db eval "SELECT $xf+0.0 AS a, \$x AS b" {
  33. puts [format "\n%.60e\n%.60e\n%.60e" $x $a $b]
  34. }
  35. }
  36. set y
  37. } {1}
  38. # Verify that round-trip real->text->real conversions using the quote()
  39. # function preserve the bits of the numeric value exactly.
  40. #
  41. do_test atof1-1.$i.2 {
  42. set y [db eval {SELECT $x=CAST(quote($x) AS real)}]
  43. if {!$y} {
  44. db eval {SELECT real2hex($x) a, real2hex(CAST(quote($x) AS real)) b} {}
  45. puts "\nIN: $a $xf"
  46. puts [format {QUOTE: %16s %s} {} [db eval {SELECT quote($x)}]]
  47. db eval {SELECT CAST(quote($x) AS real) c} {}
  48. puts "OUT: $b [format %.32e $c]"
  49. }
  50. set y
  51. } {1}
  52. }
  53. finish_test