-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Expand file tree
/
Copy pathdecimal
More file actions
90 lines (73 loc) · 2.45 KB
/
Copy pathdecimal
File metadata and controls
90 lines (73 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# The following tests have results equivalent to Postgres (differences
# in string representation and number of decimals returned, but otherwise
# the same). These do not pass using the inf package. The inf package
# (http://gopkg.in/inf.v0) is what we used to use, but it had various problems
# (for example, all the test cases below), and was replaced with apd.
# inf returns 0
query R
SELECT (1.4238790346995263e-40::DECIMAL / 6.011482313728436e+41::DECIMAL)
----
0.0000000000000000000000000000000000000000000000000000000000000000000000000000000002368598891903600
# inf returns -108.4851126682386588
query R
SELECT ln(7.682705743584112e-48::DECIMAL)
----
-108.4851126682388
# inf returns 0
query R
SELECT sqrt(9.789765531128956e-34::DECIMAL)
----
0.00000000000000003128860100919975
# inf returns 0.1547300000000000
query R
SELECT pow(4.727998800941528e-14::DECIMAL, 0.06081860494226844::DECIMAL)
----
0.1547292664070591
# inf returns 0, 0
query RR
SELECT pow(sqrt(1e-10::DECIMAL), 2), sqrt(pow(1e-5::DECIMAL, 2))
----
0.0000000001000000000000000 0.00001
# inf returns 1e-16, 0, 2e-16
query RRR
SELECT 1e-16::DECIMAL / 2, 1e-16::DECIMAL / 3, 1e-16::DECIMAL / 2 * 2
----
0.00000000000000005 0.00000000000000003333333333333333 0.00000000000000010
# inf returns 1e-8, 0, 0, 0
query RRRR
SELECT pow(1e-4::DECIMAL, 2), pow(1e-5::DECIMAL, 2), pow(1e-8::DECIMAL, 2), pow(1e-9::DECIMAL, 2)
----
0.00000001000000000000000 0.0000000001000000000000000 0.0000000000000001000000000000000 0.000000000000000001000000000000000
# inf returns argument too large
query R
SELECT pow(1e-10::DECIMAL, 2)
----
0.00000000000000000001000000000000000
# inf panics (#13051)
statement error parse mantissa: NaN
----
SELECT 'NaN'::FLOAT::DECIMAL
# Ensure trailing zeros are kept for decimal types with no listed scale,
# and enforced when the scale is listed.
statement ok
CREATE TABLE t (d decimal, v decimal(3, 1))
statement ok
INSERT INTO t VALUES (1.00::decimal, 1.00::decimal), (2.0::decimal, 2.0::decimal), (3::decimal, 3::decimal)
query RR
SELECT * FROM t ORDER BY d
----
1.00 1.0
2.0 2.0
3 3.0
# Ensure trailing zeros are kept in an index.
statement ok
CREATE TABLE t2 (d decimal, v decimal(3, 1), primary key (d, v))
statement ok
INSERT INTO t2 VALUES (1.00::decimal, 1.00::decimal), (2.0::decimal, 2.0::decimal), (3::decimal, 3::decimal)
# TODO(mjibson): enable once #13609 is merged with support for different values in index.
#query RR
#SELECT * FROM t2 ORDER BY d
#----
#1.00 1.0
#2.0 2.0
#3 3.0