1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

New test cases for the use of the ieee754 and decimal extensions in the CLI.

FossilOrigin-Name: bc1590f32fc4e2696b4126bd0302cb6405031dd4f55b86f3f1611f7f39299f85
This commit is contained in:
drh
2020-08-11 18:17:04 +00:00
parent 91faeec8d0
commit 4dfdb86c8d
3 changed files with 61 additions and 8 deletions

View File

@ -1166,4 +1166,57 @@ do_test shell1-7.1.7 {
}
# Test case for the ieee754 and decimal extensions in the shell.
# See the "floatingpoint.html" file in the documentation for more
# information.
#
do_test shell1-8.1 {
catchcmd ":memory:" {
-- The pow2 table will hold all the necessary powers of two.
CREATE TABLE pow2(x INTEGER PRIMARY KEY, v TEXT);
WITH RECURSIVE c(x,v) AS (
VALUES(0,'1')
UNION ALL
SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971
) INSERT INTO pow2(x,v) SELECT x, v FROM c;
WITH RECURSIVE c(x,v) AS (
VALUES(-1,'0.5')
UNION ALL
SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075
) INSERT INTO pow2(x,v) SELECT x, v FROM c;
-- This query finds the decimal representation of each value in the "c" table.
WITH c(n) AS (VALUES(47.49))
----XXXXX----------- Replace with whatever you want
SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v)
FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n);
}
} {0 47.49000000000000198951966012828052043914794921875}
do_test shell1-8.2 {
catchcmd :memory: {
.mode box
SELECT ieee754(47.49) AS x;
}
} {0 {┌───────────────────────────────┐
│ x │
├───────────────────────────────┤
│ ieee754(6683623321994527,-47) │
└───────────────────────────────┘}}
do_test shell1-8.3 {
catchcmd ":memory: --box" {
select ieee754(6683623321994527,-47) as x;
}
} {0 {┌───────┐
│ x │
├───────┤
│ 47.49 │
└───────┘}}
do_test shell1-8.4 {
catchcmd ":memory: --table" {SELECT ieee754_mantissa(47.49) AS M, ieee754_exponent(47.49) AS E;}
} {0 {+------------------+-----+
| M | E |
+------------------+-----+
| 6683623321994527 | -47 |
+------------------+-----+}}
finish_test