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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
" test float functions
source check.vim
CheckFeature float
source vim9.vim
func Test_abs()
call assert_equal('1.23', string(abs(1.23)))
call assert_equal('1.23', string(abs(-1.23)))
eval -1.23->abs()->string()->assert_equal('1.23')
call assert_equal('0.0', string(abs(0.0)))
call assert_equal('0.0', string(abs(1.0/(1.0/0.0))))
call assert_equal('0.0', string(abs(-1.0/(1.0/0.0))))
call assert_equal('inf', string(abs(1.0/0.0)))
call assert_equal('inf', string(abs(-1.0/0.0)))
call assert_equal('nan', string(abs(0.0/0.0)))
call assert_equal('12', string(abs('12abc')))
call assert_equal('12', string(abs('-12abc')))
call assert_fails("call abs([])", 'E745:')
call assert_fails("call abs({})", 'E728:')
call assert_fails("call abs(function('string'))", 'E703:')
endfunc
func Test_sqrt()
call assert_equal('0.0', string(sqrt(0.0)))
call assert_equal('1.414214', string(sqrt(2.0)))
eval 2.0->sqrt()->string()->assert_equal('1.414214')
call assert_equal('inf', string(sqrt(1.0/0.0)))
call assert_equal('nan', string(sqrt(-1.0)))
call assert_equal('nan', string(sqrt(0.0/0.0)))
call assert_fails('call sqrt("")', 'E808:')
endfunc
func Test_log()
call assert_equal('0.0', string(log(1.0)))
call assert_equal('-0.693147', string(log(0.5)))
eval 0.5->log()->string()->assert_equal('-0.693147')
call assert_equal('-inf', string(log(0.0)))
call assert_equal('nan', string(log(-1.0)))
call assert_equal('inf', string(log(1.0/0.0)))
call assert_equal('nan', string(log(0.0/0.0)))
call assert_fails('call log("")', 'E808:')
endfunc
func Test_log10()
call assert_equal('0.0', string(log10(1.0)))
call assert_equal('2.0', string(log10(100.0)))
call assert_equal('2.079181', string(log10(120.0)))
eval 120.0->log10()->string()->assert_equal('2.079181')
call assert_equal('-inf', string(log10(0.0)))
call assert_equal('nan', string(log10(-1.0)))
call assert_equal('inf', string(log10(1.0/0.0)))
call assert_equal('nan', string(log10(0.0/0.0)))
call assert_fails('call log10("")', 'E808:')
endfunc
func Test_exp()
call assert_equal('1.0', string(exp(0.0)))
call assert_equal('7.389056', string(exp(2.0)))
call assert_equal('0.367879', string(exp(-1.0)))
eval -1.0->exp()->string()->assert_equal('0.367879')
call assert_equal('inf', string(exp(1.0/0.0)))
call assert_equal('0.0', string(exp(-1.0/0.0)))
call assert_equal('nan', string(exp(0.0/0.0)))
call assert_fails('call exp("")', 'E808:')
endfunc
func Test_sin()
call assert_equal('0.0', string(sin(0.0)))
call assert_equal('0.841471', string(sin(1.0)))
call assert_equal('-0.479426', string(sin(-0.5)))
eval -0.5->sin()->string()->assert_equal('-0.479426')
call assert_equal('nan', string(sin(0.0/0.0)))
call assert_equal('nan', string(sin(1.0/0.0)))
call assert_equal('0.0', string(sin(1.0/(1.0/0.0))))
call assert_equal('-0.0', string(sin(-1.0/(1.0/0.0))))
call assert_fails('call sin("")', 'E808:')
endfunc
func Test_asin()
call assert_equal('0.0', string(asin(0.0)))
call assert_equal('1.570796', string(asin(1.0)))
eval 1.0->asin()->string()->assert_equal('1.570796')
call assert_equal('-0.523599', string(asin(-0.5)))
call assert_equal('nan', string(asin(1.1)))
call assert_equal('nan', string(asin(1.0/0.0)))
call assert_equal('nan', string(asin(0.0/0.0)))
call assert_fails('call asin("")', 'E808:')
endfunc
func Test_sinh()
call assert_equal('0.0', string(sinh(0.0)))
call assert_equal('0.521095', string(sinh(0.5)))
call assert_equal('-1.026517', string(sinh(-0.9)))
eval -0.9->sinh()->string()->assert_equal('-1.026517')
call assert_equal('inf', string(sinh(1.0/0.0)))
call assert_equal('-inf', string(sinh(-1.0/0.0)))
call assert_equal('nan', string(sinh(0.0/0.0)))
call assert_fails('call sinh("")', 'E808:')
endfunc
func Test_cos()
call assert_equal('1.0', string(cos(0.0)))
call assert_equal('0.540302', string(cos(1.0)))
call assert_equal('0.877583', string(cos(-0.5)))
eval -0.5->cos()->string()->assert_equal('0.877583')
call assert_equal('nan', string(cos(0.0/0.0)))
call assert_equal('nan', string(cos(1.0/0.0)))
call assert_fails('call cos("")', 'E808:')
endfunc
func Test_acos()
call assert_equal('1.570796', string(acos(0.0)))
call assert_equal('0.0', string(acos(1.0)))
call assert_equal('3.141593', string(acos(-1.0)))
eval -1.0->acos()->string()->assert_equal('3.141593')
call assert_equal('2.094395', string(acos(-0.5)))
call assert_equal('nan', string(acos(1.1)))
call assert_equal('nan', string(acos(1.0/0.0)))
call assert_equal('nan', string(acos(0.0/0.0)))
call assert_fails('call acos("")', 'E808:')
endfunc
func Test_cosh()
call assert_equal('1.0', string(cosh(0.0)))
call assert_equal('1.127626', string(cosh(0.5)))
eval 0.5->cosh()->string()->assert_equal('1.127626')
call assert_equal('inf', string(cosh(1.0/0.0)))
call assert_equal('inf', string(cosh(-1.0/0.0)))
call assert_equal('nan', string(cosh(0.0/0.0)))
call assert_fails('call cosh("")', 'E808:')
endfunc
func Test_tan()
call assert_equal('0.0', string(tan(0.0)))
call assert_equal('0.546302', string(tan(0.5)))
call assert_equal('-0.546302', string(tan(-0.5)))
eval -0.5->tan()->string()->assert_equal('-0.546302')
call assert_equal('nan', string(tan(1.0/0.0)))
call assert_equal('nan', string(cos(0.0/0.0)))
call assert_equal('0.0', string(tan(1.0/(1.0/0.0))))
call assert_equal('-0.0', string(tan(-1.0/(1.0/0.0))))
call assert_fails('call tan("")', 'E808:')
endfunc
func Test_atan()
call assert_equal('0.0', string(atan(0.0)))
call assert_equal('0.463648', string(atan(0.5)))
call assert_equal('-0.785398', string(atan(-1.0)))
eval -1.0->atan()->string()->assert_equal('-0.785398')
call assert_equal('1.570796', string(atan(1.0/0.0)))
call assert_equal('-1.570796', string(atan(-1.0/0.0)))
call assert_equal('nan', string(atan(0.0/0.0)))
call assert_fails('call atan("")', 'E808:')
endfunc
func Test_atan2()
call assert_equal('-2.356194', string(atan2(-1, -1)))
call assert_equal('2.356194', string(atan2(1, -1)))
call assert_equal('0.0', string(atan2(1.0, 1.0/0.0)))
eval 1.0->atan2(1.0/0.0)->string()->assert_equal('0.0')
call assert_equal('1.570796', string(atan2(1.0/0.0, 1.0)))
call assert_equal('nan', string(atan2(0.0/0.0, 1.0)))
call assert_fails('call atan2("", -1)', 'E808:')
call assert_fails('call atan2(-1, "")', 'E808:')
endfunc
func Test_tanh()
call assert_equal('0.0', string(tanh(0.0)))
call assert_equal('0.462117', string(tanh(0.5)))
call assert_equal('-0.761594', string(tanh(-1.0)))
eval -1.0->tanh()->string()->assert_equal('-0.761594')
call assert_equal('1.0', string(tanh(1.0/0.0)))
call assert_equal('-1.0', string(tanh(-1.0/0.0)))
call assert_equal('nan', string(tanh(0.0/0.0)))
call assert_fails('call tanh("")', 'E808:')
endfunc
func Test_fmod()
call assert_equal('0.13', string(fmod(12.33, 1.22)))
call assert_equal('-0.13', string(fmod(-12.33, 1.22)))
call assert_equal('nan', string(fmod(1.0/0.0, 1.0)))
eval (1.0/0.0)->fmod(1.0)->string()->assert_equal('nan')
" On Windows we get "nan" instead of 1.0, accept both.
let res = string(fmod(1.0, 1.0/0.0))
if res != 'nan'
call assert_equal('1.0', res)
endif
call assert_equal('nan', string(fmod(1.0, 0.0)))
call assert_fails("call fmod('', 1.22)", 'E808:')
call assert_fails("call fmod(12.33, '')", 'E808:')
endfunc
func Test_pow()
call assert_equal('1.0', string(pow(0.0, 0.0)))
call assert_equal('8.0', string(pow(2.0, 3.0)))
eval 2.0->pow(3.0)->string()->assert_equal('8.0')
call assert_equal('nan', string(pow(2.0, 0.0/0.0)))
call assert_equal('nan', string(pow(0.0/0.0, 3.0)))
call assert_equal('nan', string(pow(0.0/0.0, 3.0)))
call assert_equal('inf', string(pow(2.0, 1.0/0.0)))
call assert_equal('inf', string(pow(1.0/0.0, 3.0)))
call assert_fails("call pow('', 2.0)", 'E808:')
call assert_fails("call pow(2.0, '')", 'E808:')
endfunc
func Test_str2float()
call assert_equal('1.0', string(str2float('1')))
call assert_equal('1.0', string(str2float(' 1 ')))
call assert_equal('1.0', string(str2float(' 1.0 ')))
call assert_equal('1.23', string(str2float('1.23')))
call assert_equal('1.23',<
|