~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/func_math.test

  • Committer: Monty Taylor
  • Date: 2008-08-04 19:37:18 UTC
  • mto: (261.2.2 codestyle)
  • mto: This revision was merged to the branch mainline in revision 262.
  • Revision ID: monty@inaugust.com-20080804193718-f0rz13uli4429ozb
Changed gettext_noop() to N_()

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Test of math functions
3
 
#
4
 
 
5
 
--disable_warnings                                                              
6
 
drop table if exists t1;                                                        
7
 
--enable_warnings                                                               
8
 
 
9
 
select floor(5.5),floor(-5.5);
10
 
explain extended select floor(5.5),floor(-5.5);
11
 
select ceiling(5.5),ceiling(-5.5);
12
 
explain extended select ceiling(5.5),ceiling(-5.5);
13
 
select truncate(52.64,1),truncate(52.64,2),truncate(52.64,-1),truncate(52.64,-2), truncate(-52.64,1),truncate(-52.64,-1);
14
 
explain extended select truncate(52.64,1),truncate(52.64,2),truncate(52.64,-1),truncate(52.64,-2), truncate(-52.64,1),truncate(-52.64,-1);
15
 
select round(5.5),round(-5.5);
16
 
explain extended select round(5.5),round(-5.5);
17
 
select round(5.64,1),round(5.64,2),round(5.64,-1),round(5.64,-2);
18
 
select abs(-10), sign(-5), sign(5), sign(0);
19
 
explain extended select abs(-10), sign(-5), sign(5), sign(0);
20
 
select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2);
21
 
explain extended select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2);
22
 
select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
23
 
explain extended select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
24
 
select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
25
 
explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
26
 
select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
27
 
explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
28
 
select pow(10,log10(10)),power(2,4);
29
 
explain extended select pow(10,log10(10)),power(2,4);
30
 
set @@rand_seed1=10000000,@@rand_seed2=1000000;
31
 
select rand(999999),rand();
32
 
explain extended select rand(999999),rand();
33
 
select pi(),format(sin(pi()/2),6),format(cos(pi()/2),6),format(abs(tan(pi())),6),format(cot(1),6),format(asin(1),6),format(acos(0),6),format(atan(1),6);
34
 
explain extended select pi(),format(sin(pi()/2),6),format(cos(pi()/2),6),format(abs(tan(pi())),6),format(cot(1),6),format(asin(1),6),format(acos(0),6),format(atan(1),6);
35
 
select degrees(pi()),radians(360);
36
 
 
37
 
select format(atan(-2, 2), 6);
38
 
select format(atan(pi(), 0), 6);
39
 
select format(atan2(-2, 2), 6);
40
 
select format(atan2(pi(), 0), 6);
41
 
 
42
 
#
43
 
# Bug #2338 Trignometric arithmatic problems 
44
 
#
45
 
 
46
 
SELECT ACOS(1.0);
47
 
SELECT ASIN(1.0);
48
 
SELECT ACOS(0.2*5.0);
49
 
SELECT ACOS(0.5*2.0);
50
 
SELECT ASIN(0.8+0.2);
51
 
SELECT ASIN(1.2-0.2);
52
 
 
53
 
#
54
 
# Bug #3051 FLOOR returns invalid 
55
 
#
56
 
 
57
 
# This can't be tested as it's not portable
58
 
#select floor(log(4)/log(2));
59
 
#select floor(log(8)/log(2));
60
 
#select floor(log(16)/log(2));
61
 
 
62
 
#
63
 
# Bug #9060 (format returns incorrect result)
64
 
#
65
 
select format(4.55, 1), format(4.551, 1);
66
 
 
67
 
explain extended select degrees(pi()),radians(360);
68
 
 
69
 
#
70
 
# Bug #7281: problem with rand()
71
 
#
72
 
 
73
 
--error 1054
74
 
select rand(rand);
75
 
 
76
 
# End of 4.1 tests
77
 
 
78
 
#
79
 
# Bug #8459 (FORMAT returns incorrect result)
80
 
#
81
 
create table t1 (col1 int, col2 decimal(60,30));
82
 
insert into t1 values(1,1234567890.12345);
83
 
select format(col2,7) from t1;
84
 
select format(col2,8) from t1;
85
 
insert into t1 values(7,1234567890123456.12345);
86
 
select format(col2,6) from t1 where col1=7;
87
 
drop table t1;
88
 
 
89
 
 
90
 
#
91
 
# Bug @10632 (Ceiling function returns wrong answer)
92
 
#
93
 
select ceil(0.09);
94
 
select ceil(0.000000000000000009);
95
 
 
96
 
#
97
 
# Bug #9837: problem with round()
98
 
#
99
 
 
100
 
create table t1 select round(1, 6);
101
 
--replace_regex /ENGINE=[a-z]*/ENGINE=X/i
102
 
show create table t1;
103
 
select * from t1;
104
 
drop table t1;
105
 
 
106
 
#
107
 
# Bug #11402: abs() forces rest of calculation to
108
 
#
109
 
select abs(-2) * -2;
110
 
 
111
 
#
112
 
# Bug #6172 RAND(a) should only accept constant values as arguments
113
 
#
114
 
CREATE TABLE t1 (a INT);
115
 
 
116
 
INSERT INTO t1 VALUES (1),(1),(1),(2);
117
 
SELECT RAND(2) * 1000, RAND(a) * 1000 FROM t1;
118
 
SELECT RAND(2) * 1000, RAND(a) * 1000 FROM t1 WHERE a = 1;
119
 
INSERT INTO t1 VALUES (3);
120
 
SELECT RAND(2) * 1000, RAND(a) * 1000 FROM t1;
121
 
SELECT RAND(2) * 1000, RAND(a) * 1000 FROM t1 WHERE a = 1;
122
 
 
123
 
DROP TABLE t1;  
124
 
 
125
 
#
126
 
# Bug #14009: use of abs() on null value causes problems with filesort
127
 
#
128
 
# InnoDB is required to reproduce the fault, but it is okay if we default to
129
 
# MyISAM when testing.
130
 
--disable_warnings
131
 
create table t1 (a varchar(90), ts datetime not null, index (a)) engine=innodb;
132
 
--enable_warnings
133
 
insert into t1 values ('http://www.foo.com/', now());
134
 
select a from t1 where a='http://www.foo.com/' order by abs(timediff(ts, 0));
135
 
drop table t1;
136
 
 
137
 
# End of 4.1 tests
138
 
 
139
 
#
140
 
# Bug #8461 truncate() and round() return false results 2nd argument negative.
141
 
142
 
# round(a,-b) log_10(b) > a
143
 
select round(111,-10);
144
 
# round on bigint 
145
 
select round(-5000111000111000155,-1);
146
 
# round on bigint
147
 
select round(15000111000111000155,-1);
148
 
# truncate on bigint 
149
 
select truncate(-5000111000111000155,-1);
150
 
# truncate on bigint
151
 
select truncate(15000111000111000155,-1);
152
 
 
153
 
#
154
 
# Bug#16678 FORMAT gives wrong result if client run with default-character-set=utf8
155
 
#
156
 
create table t1
157
 
(f1 varchar(32) not null,
158
 
 f2 int not null,
159
 
 f3 int not null default '0')
160
 
engine=myisam;
161
 
insert into t1 values ('zombie',0,0),('gold',1,10000),('silver',2,10000);
162
 
 
163
 
create table t2
164
 
(f1 int not null,
165
 
 f2 int not null,
166
 
 f3 int not null)
167
 
engine=myisam;
168
 
insert into t2 values (16777216,16787215,1),(33554432,33564431,2);
169
 
 
170
 
select format(t2.f2-t2.f1+1,0) from t1,t2
171
 
where t1.f2 = t2.f3 order by t1.f1;
172
 
drop table t1, t2;
173
 
 
174
 
# Bug 24912 -- misc functions have trouble with
175
 
 
176
 
select -2, 18446744073709551614, -2;
177
 
select abs(-2), abs(18446744073709551614), abs(-2);
178
 
select ceiling(-2), ceiling(18446744073709551614), ceiling(-2);
179
 
select floor(-2), floor(18446744073709551614), floor(-2);
180
 
select format(-2, 2), format(18446744073709551614, 2), format(-2, 2);
181
 
select sqrt(-2), sqrt(18446744073709551614), sqrt(-2);
182
 
select round(-2, 1), round(18446744073709551614, 1), round(-2, 1);
183
 
select round(4, -2), round(4, 18446744073709551614), round(4, -2);
184
 
select truncate(-2, 1), truncate(18446744073709551614, 1), truncate(-2, 1);
185
 
select truncate(4, -2), truncate(4, 18446744073709551614), truncate(4, -2);
186
 
select round(10000000000000000000, -19), truncate(10000000000000000000, -19);
187
 
select round(1e0, -309), truncate(1e0, -309);
188
 
select round(1e1,308), truncate(1e1, 308);
189
 
select round(1e1, 2147483648), truncate(1e1, 2147483648);
190
 
select round(1.1e1, 4294967295), truncate(1.1e1, 4294967295);
191
 
select round(1.12e1, 4294967296), truncate(1.12e1, 4294967296);
192
 
select round(1.5, 2147483640), truncate(1.5, 2147483640);
193
 
select round(1.5, -2147483649), round(1.5, 2147483648);
194
 
select truncate(1.5, -2147483649), truncate(1.5, 2147483648);
195
 
select round(1.5, -4294967296), round(1.5, 4294967296);
196
 
select truncate(1.5, -4294967296), truncate(1.5, 4294967296);
197
 
select round(1.5, -9223372036854775808), round(1.5, 9223372036854775808);
198
 
select truncate(1.5, -9223372036854775808), truncate(1.5, 9223372036854775808);
199
 
select round(1.5, 18446744073709551615), truncate(1.5, 18446744073709551615);
200
 
select round(18446744073709551614, -1), truncate(18446744073709551614, -1);
201
 
select round(4, -4294967200), truncate(4, -4294967200);
202
 
select mod(-2, 3), mod(18446744073709551614, 3), mod(-2, 3);
203
 
select mod(5, -2), mod(5, 18446744073709551614), mod(5, -2);
204
 
select pow(-2, 5), pow(18446744073709551614, 5), pow(-2, 5);
205
 
 
206
 
#
207
 
# Bug #30587: mysql crashes when trying to group by TIME div NUMBER
208
 
#
209
 
 
210
 
CREATE TABLE t1 (a timestamp, b varchar(20), c int);
211
 
INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0);
212
 
SELECT a DIV 900 y FROM t1 GROUP BY y;
213
 
SELECT DISTINCT a DIV 900 y FROM t1;
214
 
SELECT b DIV 900 y FROM t1 GROUP BY y;
215
 
SELECT c DIV 900 y FROM t1 GROUP BY y;
216
 
DROP TABLE t1;
217
 
 
218
 
CREATE TABLE t1(a LONGBLOB);
219
 
INSERT INTO t1 VALUES('1'),('2'),('3');
220
 
SELECT DISTINCT (a DIV 254576881) FROM t1;
221
 
SELECT (a DIV 254576881) FROM t1 UNION ALL 
222
 
  SELECT (a DIV 254576881) FROM t1;
223
 
DROP TABLE t1;
224
 
 
225
 
--echo End of 5.0 tests
226
 
 
227
 
#
228
 
# Bug #31236: Inconsistent division by zero behavior for floating point numbers
229
 
#
230
 
 
231
 
SELECT 1e308 + 1e308;
232
 
SELECT -1e308 - 1e308;
233
 
SELECT 1e300 * 1e300;
234
 
SELECT 1e300 / 1e-300;
235
 
SELECT EXP(750);
236
 
SELECT POW(10, 309);
237
 
 
238
 
--echo End of 5.1 tests