2eaf93d34f
that this is happening. (CVS 5066) FossilOrigin-Name: 9b07e59e510e2de39c2081653662fbc654ca6fbb
95 lines
2.4 KiB
Plaintext
95 lines
2.4 KiB
Plaintext
# 2008 April 28
|
|
#
|
|
# 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.
|
|
#
|
|
#***********************************************************************
|
|
#
|
|
# Ticket #3060
|
|
#
|
|
# Make sure IEEE floating point NaN values are handled properly.
|
|
# SQLite should always convert NaN into NULL.
|
|
#
|
|
# $Id: nan.test,v 1.1 2008/04/29 00:15:21 drh Exp $
|
|
#
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
|
|
# The ascii->float conversion routine in SQLite converts all digits
|
|
# of a number to a long long double. Then it divids by 10**N where
|
|
# N is the number of digits to the right of the decimal point. If
|
|
# both the full number and 10**N are +Inf we will get +Inf/+Inf which
|
|
# is NaN.
|
|
#
|
|
unset -nocomplain nan
|
|
set nan 9.[string repeat 9 5000]
|
|
|
|
unset -nocomplain inf
|
|
set inf [string repeat 9 5000].0
|
|
|
|
do_test nan-1.1 {
|
|
db eval {
|
|
CREATE TABLE t1(x FLOAT);
|
|
}
|
|
db eval "INSERT INTO t1 VALUES($nan)"
|
|
db eval {SELECT x, typeof(x) FROM t1}
|
|
} {{} null}
|
|
do_test nan-1.2 {
|
|
db eval "INSERT INTO t1 VALUES($inf)"
|
|
db eval {SELECT x, typeof(x) FROM t1}
|
|
} {{} null inf real}
|
|
do_test nan-1.3 {
|
|
db eval "INSERT INTO t1 VALUES(-$inf)"
|
|
db eval {SELECT x, typeof(x) FROM t1}
|
|
} {{} null inf real -inf real}
|
|
do_test nan-1.4 {
|
|
db eval {
|
|
UPDATE t1 SET x=x-x;
|
|
SELECT x, typeof(x) FROM t1;
|
|
}
|
|
} {{} null {} null {} null}
|
|
|
|
do_test nan-2.1 {
|
|
db eval {
|
|
DELETE FROM T1;
|
|
}
|
|
db eval "INSERT INTO t1 VALUES('$nan')"
|
|
db eval {SELECT x, typeof(x) FROM t1}
|
|
} {{} null}
|
|
|
|
# SQLite always converts NaN into NULL so it is not possible to write
|
|
# a NaN value into the database file using SQLite. The following series
|
|
# of tests writes a normal floating point value (0.5) into the database,
|
|
# then writes directly into the database file to change the 0.5 into NaN.
|
|
# Then it reads the value of the database to verify it is converted into
|
|
# NULL.
|
|
#
|
|
do_test nan-3.1 {
|
|
db eval {
|
|
DELETE FROM t1;
|
|
INSERT INTO t1 VALUES(0.5);
|
|
PRAGMA auto_vacuum=OFF;
|
|
PRAGMA page_size=1024;
|
|
VACUUM;
|
|
}
|
|
hexio_read test.db 2040 8
|
|
} {3FE0000000000000}
|
|
do_test nan-3.2 {
|
|
db eval {
|
|
SELECT x, typeof(x) FROM t1
|
|
}
|
|
} {0.5 real}
|
|
do_test nan-3.3 {
|
|
db close
|
|
hexio_write test.db 2040 FFF8000000000000
|
|
sqlite3 db test.db
|
|
db eval {SELECT x, typeof(x) FROM t1}
|
|
} {{} null}
|
|
|
|
finish_test
|