Files
sqlite/test/round2.test
T
drh 190546ad7e Test cases for the round() function for values within one epsilon of the 5
round-up threshold.

FossilOrigin-Name: 552b1b106691eddb5b503c94065a1ae08d86a24f573e93fe874c48623dc28b99
2024-06-12 00:30:37 +00:00

51 lines
1.4 KiB
Plaintext

# 2024-06-10
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# https://sqlite.org/forum/forumpost/c0753dfb2d5d7f75
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix round2
load_static_extension db stmtrand ieee754
do_execsql_test 1.1 {
WITH RECURSIVE
c(n) AS (VALUES(0) UNION ALL SELECT n+1 FROM c WHERE n<100000),
r(a,b) AS MATERIALIZED (SELECT stmtrand()%100000, stmtrand()%100000 FROM c),
f(x,y,n) AS (
SELECT CAST(format('%d.%d5',a,b) AS real),
CAST(format('%d.%d6',a,b) AS real),
length(format('%d',b)) FROM r)
SELECT x, n, round(x,n), round(y,n) FROM f
WHERE round(x,n)<>round(y,n);
} {}
do_execsql_test 1.2 {
SELECT round(0.15,1);
} 0.2
do_execsql_test 1.3 {
SELECT round(0.14999999999999999,1);
} 0.2
do_execsql_test 1.4 {
SELECT round(0.1499999999999999944488848768742172978818416595458984375,1);
} 0.2
do_execsql_test 1.5 {
SELECT round(ieee754_from_blob(x'3fc3333333333333'),1);
} 0.2
do_execsql_test 1.6 {
SELECT round(ieee754_from_blob(x'3fc3333333333332'),1);
} 0.1
finish_test