CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
fpconv1.test45 linesDownload Raw Back to test
1# 2023-07-032#3# The author disclaims copyright to this source code.  In place of4# 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# This file contains a test that attempts to verify the claim that the13# floatpoint-to-text conversion routines built into SQLite maintain at14# least 15 significant digits of accuracy.15#16 17set testdir [file dirname $argv0]18source $testdir/tester.tcl19 20if {[catch {load_static_extension db decimal} error]} {21  puts "Skipping decimal tests, hit load error: $error"22  finish_test; return23}24 25sqlite3_create_function db26do_execsql_test fpconv1-1.0 {27  WITH RECURSIVE28       /* Number of random floating-point values to try.29       ** On a circa 2016 x64 linux box, this test runs at30       ** 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 c36    )37  SELECT y FROM fp38   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 numbers42#        that fail to preserve at least 15 significant digits of accuracy.43 44finish_test45