interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / ieee754.test

86 lines · 2553 bytes Raw Blame History
1# 2015-11-06
2#
3# The author disclaims copyright to this source code. In place of
4# 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# Tests of the iee754 extension
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17
18load_static_extension db ieee754
19
20foreach {id float rep} {
21 1 1.0 1,0
22 2 2.0 2,0
23 3 0.5 1,-1
24 4 1.5 3,-1
25 5 0.0 0,-1075
26 6 4.9406564584124654e-324 1,-1074
27 7 2.2250738585072009e-308 4503599627370495,-1074
28 8 2.2250738585072014e-308 1,-1022
29} {
30 do_test ieee754-100-$id-1 {
31 db eval "SELECT ieee754($float);"
32 } "ieee754($rep)"
33 do_test ieee754-100-$id-2 {
34 db eval "SELECT ieee754($rep)==$float;"
35 } {1}
36 if {$float!=0.0} {
37 do_test ieee754-100-$id-3 {
38 db eval "SELECT ieee754(-$float);"
39 } "ieee754(-$rep)"
40 do_test ieee754-100-$id-4 {
41 db eval "SELECT ieee754(-$rep)==-$float;"
42 } {1}
43 }
44}
45
46do_test ieee754-110 {
47 string tolower [
48 db eval {SELECT ieee754(1,1024), ieee754(4503599627370495,972);}
49 ]
50} {inf 1.79769313486232e+308}
51do_test ieee754-111 {
52 string tolower [
53 db eval {SELECT ieee754(-1,1024), ieee754(-4503599627370495,972);}
54 ]
55} {-inf -1.79769313486232e+308}
56do_execsql_test ieee754-112 {
57 SELECT ieee754(4503599627370495,973) is null;
58} {1}
59
60do_execsql_test ieee754-200 {
61 SELECT ieee754(0.0), hex(ieee754_to_blob(ieee754(0,-1075)));
62} {ieee754(0,-1075) 0000000000000000}
63
64# Special case. -0.0 is rendered as ieee754(-1,-3071).
65#
66do_execsql_test ieee754-201 {
67 SELECT ieee754(-0.0), hex(ieee754_to_blob(ieee754(-1,-3071)));
68} {ieee754(-1,-3071) 8000000000000000}
69
70# A zero mantissa gives zero, whatever the exponent. Formerly the result
71# was Inf or an exact power of two for exponents outside -1000<Z<1000.
72#
73do_execsql_test ieee754-202 {
74 SELECT ieee754(0,999), ieee754(0,1000), ieee754(0,-1000), ieee754(0,-1074),
75 ieee754(0,10000), ieee754(0,-10000);
76} {0.0 0.0 0.0 0.0 0.0 0.0}
77
78# The -0.0 encoding uses a negative mantissa, so it is unaffected.
79#
80do_execsql_test ieee754-203 {
81 SELECT ieee754(-0.0), hex(ieee754_to_blob(ieee754(-1,-3071)));
82} {ieee754(-1,-3071) 8000000000000000}
83
84
85
86finish_test