annotate src/testdir/test_float_func.vim @ 22502:1503ecd54f8a v8.2.1799

patch 8.2.1799: some Normal mode commands not fully tested Commit: https://github.com/vim/vim/commit/d1ad99b65470d3e754f6a0588a6b0dc2214a1eab Author: Bram Moolenaar <Bram@vim.org> Date: Sun Oct 4 16:16:54 2020 +0200 patch 8.2.1799: some Normal mode commands not fully tested Problem: Some Normal mode commands not fully tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/7073)
author Bram Moolenaar <Bram@vim.org>
date Sun, 04 Oct 2020 16:30:03 +0200
parents 545119cd5554
children 5f8dd7b3ae41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " test float functions
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
17089
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
3 source check.vim
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
4 CheckFeature float
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 func Test_abs()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
7 call assert_equal('1.23', string(abs(1.23)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
8 call assert_equal('1.23', string(abs(-1.23)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
9 eval -1.23->abs()->string()->assert_equal('1.23')
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
10
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
11 call assert_equal('0.0', string(abs(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
12 call assert_equal('0.0', string(abs(1.0/(1.0/0.0))))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
13 call assert_equal('0.0', string(abs(-1.0/(1.0/0.0))))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
14 call assert_equal('inf', string(abs(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
15 call assert_equal('inf', string(abs(-1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
16 call assert_equal('nan', string(abs(0.0/0.0)))
16668
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 16213
diff changeset
17 call assert_equal('12', string(abs('12abc')))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
18 call assert_equal('12', string(abs('-12abc')))
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
19 call assert_fails("call abs([])", 'E745:')
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
20 call assert_fails("call abs({})", 'E728:')
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
21 call assert_fails("call abs(function('string'))", 'E703:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 func Test_sqrt()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
25 call assert_equal('0.0', string(sqrt(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
26 call assert_equal('1.414214', string(sqrt(2.0)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
27 eval 2.0->sqrt()->string()->assert_equal('1.414214')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
28 call assert_equal('inf', string(sqrt(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
29 call assert_equal('nan', string(sqrt(-1.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
30 call assert_equal('nan', string(sqrt(0.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
31 call assert_fails('call sqrt("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 func Test_log()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
35 call assert_equal('0.0', string(log(1.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
36 call assert_equal('-0.693147', string(log(0.5)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
37 eval 0.5->log()->string()->assert_equal('-0.693147')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
38 call assert_equal('-inf', string(log(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
39 call assert_equal('nan', string(log(-1.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
40 call assert_equal('inf', string(log(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
41 call assert_equal('nan', string(log(0.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
42 call assert_fails('call log("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 func Test_log10()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
46 call assert_equal('0.0', string(log10(1.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
47 call assert_equal('2.0', string(log10(100.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
48 call assert_equal('2.079181', string(log10(120.0)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
49 eval 120.0->log10()->string()->assert_equal('2.079181')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
50 call assert_equal('-inf', string(log10(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
51 call assert_equal('nan', string(log10(-1.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
52 call assert_equal('inf', string(log10(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
53 call assert_equal('nan', string(log10(0.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
54 call assert_fails('call log10("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 func Test_exp()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
58 call assert_equal('1.0', string(exp(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
59 call assert_equal('7.389056', string(exp(2.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
60 call assert_equal('0.367879', string(exp(-1.0)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
61 eval -1.0->exp()->string()->assert_equal('0.367879')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
62 call assert_equal('inf', string(exp(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
63 call assert_equal('0.0', string(exp(-1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
64 call assert_equal('nan', string(exp(0.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
65 call assert_fails('call exp("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 func Test_sin()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
69 call assert_equal('0.0', string(sin(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
70 call assert_equal('0.841471', string(sin(1.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
71 call assert_equal('-0.479426', string(sin(-0.5)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
72 eval -0.5->sin()->string()->assert_equal('-0.479426')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
73 call assert_equal('nan', string(sin(0.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
74 call assert_equal('nan', string(sin(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
75 call assert_equal('0.0', string(sin(1.0/(1.0/0.0))))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
76 call assert_equal('-0.0', string(sin(-1.0/(1.0/0.0))))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
77 call assert_fails('call sin("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 func Test_asin()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
81 call assert_equal('0.0', string(asin(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
82 call assert_equal('1.570796', string(asin(1.0)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
83 eval 1.0->asin()->string()->assert_equal('1.570796')
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
84
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
85 call assert_equal('-0.523599', string(asin(-0.5)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
86 call assert_equal('nan', string(asin(1.1)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
87 call assert_equal('nan', string(asin(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
88 call assert_equal('nan', string(asin(0.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
89 call assert_fails('call asin("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 func Test_sinh()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
93 call assert_equal('0.0', string(sinh(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
94 call assert_equal('0.521095', string(sinh(0.5)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
95 call assert_equal('-1.026517', string(sinh(-0.9)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
96 eval -0.9->sinh()->string()->assert_equal('-1.026517')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
97 call assert_equal('inf', string(sinh(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
98 call assert_equal('-inf', string(sinh(-1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
99 call assert_equal('nan', string(sinh(0.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
100 call assert_fails('call sinh("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 func Test_cos()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
104 call assert_equal('1.0', string(cos(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
105 call assert_equal('0.540302', string(cos(1.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
106 call assert_equal('0.877583', string(cos(-0.5)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
107 eval -0.5->cos()->string()->assert_equal('0.877583')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
108 call assert_equal('nan', string(cos(0.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
109 call assert_equal('nan', string(cos(1.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
110 call assert_fails('call cos("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 func Test_acos()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
114 call assert_equal('1.570796', string(acos(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
115 call assert_equal('0.0', string(acos(1.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
116 call assert_equal('3.141593', string(acos(-1.0)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
117 eval -1.0->acos()->string()->assert_equal('3.141593')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
118 call assert_equal('2.094395', string(acos(-0.5)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
119 call assert_equal('nan', string(acos(1.1)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
120 call assert_equal('nan', string(acos(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
121 call assert_equal('nan', string(acos(0.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
122 call assert_fails('call acos("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 func Test_cosh()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
126 call assert_equal('1.0', string(cosh(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
127 call assert_equal('1.127626', string(cosh(0.5)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
128 eval 0.5->cosh()->string()->assert_equal('1.127626')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
129 call assert_equal('inf', string(cosh(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
130 call assert_equal('inf', string(cosh(-1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
131 call assert_equal('nan', string(cosh(0.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
132 call assert_fails('call cosh("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 func Test_tan()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
136 call assert_equal('0.0', string(tan(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
137 call assert_equal('0.546302', string(tan(0.5)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
138 call assert_equal('-0.546302', string(tan(-0.5)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
139 eval -0.5->tan()->string()->assert_equal('-0.546302')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
140 call assert_equal('nan', string(tan(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
141 call assert_equal('nan', string(cos(0.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
142 call assert_equal('0.0', string(tan(1.0/(1.0/0.0))))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
143 call assert_equal('-0.0', string(tan(-1.0/(1.0/0.0))))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
144 call assert_fails('call tan("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 func Test_atan()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
148 call assert_equal('0.0', string(atan(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
149 call assert_equal('0.463648', string(atan(0.5)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
150 call assert_equal('-0.785398', string(atan(-1.0)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
151 eval -1.0->atan()->string()->assert_equal('-0.785398')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
152 call assert_equal('1.570796', string(atan(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
153 call assert_equal('-1.570796', string(atan(-1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
154 call assert_equal('nan', string(atan(0.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
155 call assert_fails('call atan("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 func Test_atan2()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
159 call assert_equal('-2.356194', string(atan2(-1, -1)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
160 call assert_equal('2.356194', string(atan2(1, -1)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
161 call assert_equal('0.0', string(atan2(1.0, 1.0/0.0)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
162 eval 1.0->atan2(1.0/0.0)->string()->assert_equal('0.0')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
163 call assert_equal('1.570796', string(atan2(1.0/0.0, 1.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
164 call assert_equal('nan', string(atan2(0.0/0.0, 1.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
165 call assert_fails('call atan2("", -1)', 'E808:')
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
166 call assert_fails('call atan2(-1, "")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 func Test_tanh()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
170 call assert_equal('0.0', string(tanh(0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
171 call assert_equal('0.462117', string(tanh(0.5)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
172 call assert_equal('-0.761594', string(tanh(-1.0)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
173 eval -1.0->tanh()->string()->assert_equal('-0.761594')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
174 call assert_equal('1.0', string(tanh(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
175 call assert_equal('-1.0', string(tanh(-1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
176 call assert_equal('nan', string(tanh(0.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
177 call assert_fails('call tanh("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
178 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 func Test_fmod()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
181 call assert_equal('0.13', string(fmod(12.33, 1.22)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
182 call assert_equal('-0.13', string(fmod(-12.33, 1.22)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
183 call assert_equal('nan', string(fmod(1.0/0.0, 1.0)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
184 eval (1.0/0.0)->fmod(1.0)->string()->assert_equal('nan')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
185 " On Windows we get "nan" instead of 1.0, accept both.
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
186 let res = string(fmod(1.0, 1.0/0.0))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
187 if res != 'nan'
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
188 call assert_equal('1.0', res)
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
189 endif
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
190 call assert_equal('nan', string(fmod(1.0, 0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
191 call assert_fails("call fmod('', 1.22)", 'E808:')
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
192 call assert_fails("call fmod(12.33, '')", 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
195 func Test_pow()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
196 call assert_equal('1.0', string(pow(0.0, 0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
197 call assert_equal('8.0', string(pow(2.0, 3.0)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
198 eval 2.0->pow(3.0)->string()->assert_equal('8.0')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
199 call assert_equal('nan', string(pow(2.0, 0.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
200 call assert_equal('nan', string(pow(0.0/0.0, 3.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
201 call assert_equal('nan', string(pow(0.0/0.0, 3.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
202 call assert_equal('inf', string(pow(2.0, 1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
203 call assert_equal('inf', string(pow(1.0/0.0, 3.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
204 call assert_fails("call pow('', 2.0)", 'E808:')
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
205 call assert_fails("call pow(2.0, '')", 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
206 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
207
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
208 func Test_str2float()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
209 call assert_equal('1.0', string(str2float('1')))
10555
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
210 call assert_equal('1.0', string(str2float(' 1 ')))
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
211 call assert_equal('1.0', string(str2float(' 1.0 ')))
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
212 call assert_equal('1.23', string(str2float('1.23')))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
213 call assert_equal('1.23', string(str2float('1.23abc')))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
214 eval '1.23abc'->str2float()->string()->assert_equal('1.23')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
215 call assert_equal('1.0e40', string(str2float('1e40')))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
216 call assert_equal('-1.23', string(str2float('-1.23')))
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
217 call assert_equal('1.23', string(str2float(' + 1.23 ')))
10555
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
218
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
219 call assert_equal('1.0', string(str2float('+1')))
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
220 call assert_equal('1.0', string(str2float('+1')))
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
221 call assert_equal('1.0', string(str2float(' +1 ')))
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
222 call assert_equal('1.0', string(str2float(' + 1 ')))
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
223
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
224 call assert_equal('-1.0', string(str2float('-1')))
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
225 call assert_equal('-1.0', string(str2float('-1')))
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
226 call assert_equal('-1.0', string(str2float(' -1 ')))
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
227 call assert_equal('-1.0', string(str2float(' - 1 ')))
fff45421182b patch 8.0.0167: str2nr()/str2float() fail with negative values
Christian Brabandt <cb@256bit.org>
parents: 10536
diff changeset
228
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
229 call assert_equal('0.0', string(str2float('+0.0')))
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
230 call assert_equal('-0.0', string(str2float('-0.0')))
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
231 call assert_equal('inf', string(str2float('1e1000')))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
232 call assert_equal('inf', string(str2float('inf')))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
233 call assert_equal('-inf', string(str2float('-inf')))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
234 call assert_equal('inf', string(str2float('+inf')))
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
235 call assert_equal('inf', string(str2float('Inf')))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
236 call assert_equal('inf', string(str2float(' +inf ')))
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
237 call assert_equal('nan', string(str2float('nan')))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
238 call assert_equal('nan', string(str2float('NaN')))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
239 call assert_equal('nan', string(str2float(' nan ')))
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
240
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
241 call assert_fails("call str2float(1.2)", 'E806:')
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
242 call assert_fails("call str2float([])", 'E730:')
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
243 call assert_fails("call str2float({})", 'E731:')
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
244 call assert_fails("call str2float(function('string'))", 'E729:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
245 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
246
11461
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
247 func Test_float2nr()
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
248 call assert_equal(1, float2nr(1.234))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
249 call assert_equal(123, float2nr(1.234e2))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
250 call assert_equal(12, float2nr(123.4e-1))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
251 eval 123.4e-1->float2nr()->assert_equal(12)
11461
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
252 let max_number = 1/0
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
253 let min_number = -max_number
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
254 call assert_equal(max_number/2+1, float2nr(pow(2, 62)))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
255 call assert_equal(max_number, float2nr(pow(2, 63)))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
256 call assert_equal(max_number, float2nr(pow(2, 64)))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
257 call assert_equal(min_number/2-1, float2nr(-pow(2, 62)))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
258 call assert_equal(min_number, float2nr(-pow(2, 63)))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
259 call assert_equal(min_number, float2nr(-pow(2, 64)))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
260 endfunc
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
261
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
262 func Test_floor()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
263 call assert_equal('2.0', string(floor(2.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
264 call assert_equal('2.0', string(floor(2.11)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
265 call assert_equal('2.0', string(floor(2.99)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
266 eval 2.99->floor()->string()->assert_equal('2.0')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
267 call assert_equal('-3.0', string(floor(-2.11)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
268 call assert_equal('-3.0', string(floor(-2.99)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
269 call assert_equal('nan', string(floor(0.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
270 call assert_equal('inf', string(floor(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
271 call assert_equal('-inf', string(floor(-1.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
272 call assert_fails("call floor('')", 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
273 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
274
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
275 func Test_ceil()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
276 call assert_equal('2.0', string(ceil(2.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
277 call assert_equal('3.0', string(ceil(2.11)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
278 call assert_equal('3.0', string(ceil(2.99)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
279 call assert_equal('-2.0', string(ceil(-2.11)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
280 eval -2.11->ceil()->string()->assert_equal('-2.0')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
281 call assert_equal('-2.0', string(ceil(-2.99)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
282 call assert_equal('nan', string(ceil(0.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
283 call assert_equal('inf', string(ceil(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
284 call assert_equal('-inf', string(ceil(-1.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
285 call assert_fails("call ceil('')", 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
286 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
287
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
288 func Test_round()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
289 call assert_equal('2.0', string(round(2.1)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
290 call assert_equal('3.0', string(round(2.5)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
291 call assert_equal('3.0', string(round(2.9)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
292 eval 2.9->round()->string()->assert_equal('3.0')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
293 call assert_equal('-2.0', string(round(-2.1)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
294 call assert_equal('-3.0', string(round(-2.5)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
295 call assert_equal('-3.0', string(round(-2.9)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
296 call assert_equal('nan', string(round(0.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
297 call assert_equal('inf', string(round(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
298 call assert_equal('-inf', string(round(-1.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
299 call assert_fails("call round('')", 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
300 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
301
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
302 func Test_trunc()
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
303 call assert_equal('2.0', string(trunc(2.1)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
304 call assert_equal('2.0', string(trunc(2.5)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
305 call assert_equal('2.0', string(trunc(2.9)))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
306 eval 2.9->trunc()->string()->assert_equal('2.0')
10536
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
307 call assert_equal('-2.0', string(trunc(-2.1)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
308 call assert_equal('-2.0', string(trunc(-2.5)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
309 call assert_equal('-2.0', string(trunc(-2.9)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
310 call assert_equal('nan', string(trunc(0.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
311 call assert_equal('inf', string(trunc(1.0/0.0)))
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
312 call assert_equal('-inf', string(trunc(-1.0/0.0)))
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
313 call assert_fails("call trunc('')", 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
314 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
315
16213
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
316 func Test_isinf()
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
317 call assert_equal(1, isinf(1.0/0.0))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
318 call assert_equal(-1, isinf(-1.0/0.0))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
319 eval (-1.0/0.0)->isinf()->assert_equal(-1)
16213
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
320 call assert_false(isinf(1.0))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
321 call assert_false(isinf(0.0/0.0))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
322 call assert_false(isinf('a'))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
323 call assert_false(isinf([]))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
324 call assert_false(isinf({}))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
325 endfunc
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
326
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
327 func Test_isnan()
16213
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
328 call assert_true(isnan(0.0/0.0))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
329 call assert_false(isnan(1.0))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
330 call assert_false(isnan(1.0/0.0))
17765
545119cd5554 patch 8.1.1879: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
331 eval (1.0/0.0)->isnan()->assert_false()
16213
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
332 call assert_false(isnan(-1.0/0.0))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
333 call assert_false(isnan('a'))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
334 call assert_false(isnan([]))
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
335 call assert_false(isnan({}))
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
336 endfunc
11461
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
337
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
338 " This was converted from test65
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
339 func Test_float_misc()
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
340 call assert_equal('123.456000', printf('%f', 123.456))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
341 call assert_equal('1.234560e+02', printf('%e', 123.456))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
342 call assert_equal('123.456', printf('%g', 123.456))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
343 " +=
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
344 let v = 1.234
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
345 let v += 6.543
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
346 call assert_equal('7.777', printf('%g', v))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
347 let v = 1.234
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
348 let v += 5
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
349 call assert_equal('6.234', printf('%g', v))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
350 let v = 5
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
351 let v += 3.333
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
352 call assert_equal('8.333', string(v))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
353 " ==
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
354 let v = 1.234
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
355 call assert_true(v == 1.234)
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
356 call assert_false(v == 1.2341)
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
357 " add-subtract
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
358 call assert_equal('5.234', printf('%g', 4 + 1.234))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
359 call assert_equal('-6.766', printf('%g', 1.234 - 8))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
360 " mult-div
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
361 call assert_equal('4.936', printf('%g', 4 * 1.234))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
362 call assert_equal('0.003241', printf('%g', 4.0 / 1234))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
363 " dict
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
364 call assert_equal("{'x': 1.234, 'y': -2.0e20}", string({'x': 1.234, 'y': -2.0e20}))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
365 " list
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
366 call assert_equal('[-123.4, 2.0e-20]', string([-123.4, 2.0e-20]))
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
367 endfunc
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
368
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
369 " vim: shiftwidth=2 sts=2 expandtab