3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
12 # Test cases for SQL functions based off the standard math library
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
21 do_execsql_test func7-100 {
22 SELECT ceil(99.9), ceiling(-99.01), floor(17), floor(-17.99);
23 } {100.0 -99.0 17 -18.0}
24 do_execsql_test func7-110 {
25 SELECT quote(ceil(NULL)), ceil('-99.99');
27 do_execsql_test func7-200 {
28 SELECT round(ln(5),2), log(100.0), log(100), log(2,'256');
30 do_execsql_test func7-210 {
31 SELECT ln(-5), log(-5,100.0);
34 # Test cases derived from PostgreSQL documentation
36 do_execsql_test func7-pg-100 {
39 do_execsql_test func7-pg-110 {
42 do_execsql_test func7-pg-120 {
45 do_execsql_test func7-pg-130 {
46 SELECT round(exp(1.0),7)
48 do_execsql_test func7-pg-140 {
51 do_execsql_test func7-pg-150 {
54 do_execsql_test func7-pg-160 {
55 SELECT round(ln(2.0),7)
57 do_execsql_test func7-pg-170 {
60 do_execsql_test func7-pg-180 {
63 do_execsql_test func7-pg-181 {
64 SELECT format('%.30f', log10(100.0) );
65 } {2.000000000000000000000000000000}
66 do_execsql_test func7-pg-182 {
67 SELECT format('%.30f', ln(exp(2.0)) );
68 } {2.000000000000000000000000000000}
69 do_execsql_test func7-pg-190 {
72 do_execsql_test func7-pg-200 {
75 do_execsql_test func7-pg-210 {
78 do_execsql_test func7-pg-220 {
81 do_execsql_test func7-pg-230 {
82 SELECT round(radians(45.0),7);
84 do_execsql_test func7-pg-240 {
87 do_execsql_test func7-pg-250 {
88 SELECT round(42.4382,2);
90 do_execsql_test func7-pg-260 {
93 do_execsql_test func7-pg-270 {
94 SELECT round( sqrt(2), 7);
96 do_execsql_test func7-pg-280 {
97 SELECT trunc(42.8), trunc(-42.8);
99 do_execsql_test func7-pg-300 {
102 do_execsql_test func7-pg-301 {
103 SELECT degrees(acos(0.5));
105 do_execsql_test func7-pg-310 {
106 SELECT round( asin(1), 7);
108 do_execsql_test func7-pg-311 {
109 SELECT degrees( asin(0.5) );
111 do_execsql_test func7-pg-320 {
112 SELECT round( atan(1), 7);
114 do_execsql_test func7-pg-321 {
115 SELECT degrees( atan(1) );
117 do_execsql_test func7-pg-330 {
118 SELECT round( atan2(1,0), 7);
120 do_execsql_test func7-pg-331 {
121 SELECT degrees( atan2(1,0) );
123 do_execsql_test func7-pg-400 {
126 do_execsql_test func7-pg-401 {
127 SELECT cos( radians(60.0) );
129 do_execsql_test func7-pg-400 {
132 do_execsql_test func7-pg-410 {
133 SELECT round( sin(1), 7);
135 do_execsql_test func7-pg-411 {
136 SELECT sin( radians(30) );
138 do_execsql_test func7-pg-420 {
139 SELECT round( tan(1), 7);
141 do_execsql_test func7-pg-421 {
142 SELECT tan( radians(45) );
144 do_execsql_test func7-pg-500 {
145 SELECT round( sinh(1), 7);
147 do_execsql_test func7-pg-510 {
148 SELECT round( cosh(0), 7);
150 do_execsql_test func7-pg-520 {
151 SELECT round( tanh(1), 7);
153 do_execsql_test func7-pg-530 {
154 SELECT round( asinh(1), 7);
156 do_execsql_test func7-pg-540 {
157 SELECT round( acosh(1), 7);
159 do_execsql_test func7-pg-550 {
160 SELECT round( atanh(0.5), 7);
163 # Test cases derived from MySQL documentation
165 do_execsql_test func7-mysql-100 {
168 do_execsql_test func7-mysql-110 {
171 do_execsql_test func7-mysql-120 {
172 SELECT round( acos(0.0), 7);
174 do_execsql_test func7-mysql-130 {
175 SELECT round( asin(0.2), 7);
177 do_execsql_test func7-mysql-140 {
179 } {{}} ;# Note: MySQL returns 0 here, not NULL.
180 # SQLite deliberately returns NULL.
181 # SQLServer and Oracle throw an error.
182 do_execsql_test func7-mysql-150 {
183 SELECT round( atan(2), 7), round( atan(-2), 7);
184 } {1.1071487 -1.1071487}
185 do_execsql_test func7-mysql-160 {
186 SELECT round( atan2(-2,2), 7), round( atan2(pi(),0), 7);
187 } {-0.7853982 1.5707963}
188 do_execsql_test func7-mysql-170 {
189 SELECT ceiling(1.23), ceiling(-1.23);
191 do_execsql_test func7-mysql-180 {
194 do_execsql_test func7-mysql-190 {
195 SELECT degrees(pi()), degrees(pi()/2);
197 do_execsql_test func7-mysql-190 {
198 SELECT round( exp(2), 7), round( exp(-2), 7), exp(0);
199 } {7.3890561 0.1353353 1.0}
200 do_execsql_test func7-mysql-200 {
201 SELECT floor(1.23), floor(-1.23);
203 do_execsql_test func7-mysql-210 {
204 SELECT round(ln(2),7), quote(ln(-2));
206 #do_execsql_test func7-mysql-220 {
207 # SELECT round(log(2),7), log(-2);
209 # log() means natural logarithm in MySQL
210 do_execsql_test func7-mysql-230 {
211 SELECT log(2,65536), log(10,100), quote(log(1,100)), quote(log(0,100));
212 } {16.0 2.0 NULL NULL}
213 do_execsql_test func7-mysql-240 {
214 SELECT log2(65536), quote(log2(-100)), quote(log2(0));
216 do_execsql_test func7-mysql-250 {
217 SELECT round(log10(2),7), log10(100), quote(log10(-100));
219 do_execsql_test func7-mysql-260 {
220 SELECT mod(234,10), 253%7, mod(29,9), 29%9;
222 do_execsql_test func7-mysql-270 {
225 do_execsql_test func7-mysql-280 {
226 SELECT pow(2,2), pow(2,-2);
228 do_execsql_test func7-mysql-281 {
229 SELECT power(2,2), power(2,-2);
231 do_execsql_test func7-mysql-290 {
232 SELECT round(radians(90),7);
234 do_execsql_test func7-mysql-300 {
235 SELECT sign(-32), sign(0), sign(234);
237 do_execsql_test func7-mysql-310 {
238 SELECT sin(pi()) BETWEEN -1.0e-15 AND 1.0e-15;
240 do_execsql_test func7-mysql-320 {
241 SELECT sqrt(4), round(sqrt(20),7), quote(sqrt(-16));
242 } {2.0 4.472136 NULL}
243 do_execsql_test func7-mysql-330 {
244 SELECT tan(pi()) BETWEEN -1.0e-15 AND 1.0e-15;
246 do_execsql_test func7-mysql-331 {
247 SELECT round(tan(pi()+1),7);