Testrunner.tcl enhancements: (1) Attempt to build the SQLite tcl extension
[sqlite.git] / test / fpconv1.test
blob195fdf990488feaaa8cfb2057ec174a95ee44be8
1 # 2023-07-03
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11
12 # This file contains a test that attempts to verify the claim that the
13 # floatpoint-to-text conversion routines built into SQLite maintain at
14 # least 15 significant digits of accuracy.
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 if {[catch {load_static_extension db decimal} error]} {
21   puts "Skipping decimal tests, hit load error: $error"
22   finish_test; return
25 sqlite3_create_function db
26 do_execsql_test fpconv1-1.0 {
27   WITH RECURSIVE
28        /* Number of random floating-point values to try.
29        ** On a circa 2016 x64 linux box, this test runs at
30        ** about 80000 cases per second  -------------------vvvvvv */
31     c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100000),
32     fp(y) AS MATERIALIZED (
33        SELECT CAST( format('%+d.%019d0e%+03d',
34                            random()%10,abs(random()),random()%200) AS real)
35         FROM c
36     )
37   SELECT y FROM fp
38    WHERE -log10(abs(decimal_sub(dtostr(y,24),format('%!.24e',y))/y))<15.0;
39                      /* Number of digits of accuracy required -------^^^^ */
40 } {}
41 #  ^---- Expect a empty set as the result.  The output is all tested numbers
42 #        that fail to preserve at least 15 significant digits of accuracy.
44 finish_test