annotate src/testdir/test_float_func.vim @ 29334:72d1b2ea70dc v9.0.0010

patch 9.0.0010: returning 0 for has('patch-9.0.0') is inconsistent Commit: https://github.com/vim/vim/commit/b0375d466e5ca57dca71995c342870b3226d8115 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 30 11:03:39 2022 +0100 patch 9.0.0010: returning 0 for has('patch-9.0.0') is inconsistent Problem: Returning 0 for has('patch-9.0.0') is inconsistent. Solution: Make it return 1. (closes https://github.com/vim/vim/issues/10640)
author Bram Moolenaar <Bram@vim.org>
date Thu, 30 Jun 2022 12:15:04 +0200
parents 4c16acb2525f
children 029c59bf78f1
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
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
5 import './vim9.vim' as v9
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 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
8 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
9 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
10 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
11
10536
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(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('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
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('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
17 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
18 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
19 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
20 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
21 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
22 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
23 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 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
26 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
27 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
28 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
29 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
30 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
31 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
32 call assert_fails('call sqrt("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 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
36 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
37 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
38 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
39 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
40 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
41 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
42 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
43 call assert_fails('call log("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55 call assert_fails('call log10("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 call assert_fails('call exp("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 call assert_fails('call sin("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 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
82 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
83 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
84 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
85
10536
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('-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
87 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
88 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
89 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
90 call assert_fails('call asin("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 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
94 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
95 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
96 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
97 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
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('-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
100 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
101 call assert_fails('call sinh("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 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
105 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
106 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
107 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
108 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
109 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
110 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
111 call assert_fails('call cos("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 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
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 call assert_fails('call acos("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 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
127 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
128 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
129 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
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('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
132 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
133 call assert_fails('call cosh("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 call assert_fails('call tan("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 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
149 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
150 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
151 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
152 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
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('-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
155 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
156 call assert_fails('call atan("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 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
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('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
162 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
163 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
164 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
165 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
166 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
167 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
168 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 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
171 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
172 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
173 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
174 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
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('-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
177 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
178 call assert_fails('call tanh("")', 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
181 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
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('-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
184 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
185 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
186 " 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
187 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
188 if res != 'nan'
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
189 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
190 endif
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10532
diff changeset
191 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
192 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
193 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
194 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
195
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
196 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
197 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
198 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
199 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
200 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
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('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
203 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
204 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
205 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
206 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
207 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
208
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219
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 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
224
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 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
229
10557
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')))
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
231 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
232 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
233 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
234 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
235 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
236 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
237 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
238 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
239 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
240 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
241
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
242 call assert_equal('123456.789', string(str2float("123'456.789", 1)))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
243 call assert_equal('123456.789', string(str2float("12'34'56.789", 1)))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
244 call assert_equal('123456.789', string(str2float("1'2'3'4'5'6.789", 1)))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
245 call assert_equal('1.0', string(str2float("1''2.3", 1)))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
246 call assert_equal('123456.7', string(str2float("123'456.7'89", 1)))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
247
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
248 call assert_equal(1.2, str2float(1.2, 0))
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
249 call v9.CheckDefAndScriptFailure(['str2float(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
10557
018b7ecc58db patch 8.0.0168: not all float functionality is tested
Christian Brabandt <cb@256bit.org>
parents: 10555
diff changeset
250 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
251 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
252 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
253 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
255 def Test_float_quotes()
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
256 call assert_equal('123456.789', string(123'456.789))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
257 call assert_equal('123456.789', string(12'34'56.789))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
258 call assert_equal('123456.789', string(1'2'3'4'5'6.789))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
259
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
260 call assert_fails("echo string(1''2.3)", 'E116:')
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
261 call assert_fails("echo string(123'456.7'89)", 'E116:')
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
262 enddef
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
263
25563
10605253d009 patch 8.2.3318: Vim9: cannot ignore quotes in number at the command line
Bram Moolenaar <Bram@vim.org>
parents: 25557
diff changeset
264 func Test_float_quotes_from_legacy()
10605253d009 patch 8.2.3318: Vim9: cannot ignore quotes in number at the command line
Bram Moolenaar <Bram@vim.org>
parents: 25557
diff changeset
265 call assert_equal("\n123456.789", execute("vim9 echo 12'34'56.789"))
10605253d009 patch 8.2.3318: Vim9: cannot ignore quotes in number at the command line
Bram Moolenaar <Bram@vim.org>
parents: 25557
diff changeset
266 endfunc
10605253d009 patch 8.2.3318: Vim9: cannot ignore quotes in number at the command line
Bram Moolenaar <Bram@vim.org>
parents: 25557
diff changeset
267
11461
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
268 func Test_float2nr()
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
269 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
270 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
271 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
272 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
273 let max_number = 1/0
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
274 let min_number = -max_number
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
275 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
276 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
277 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
278 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
279 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
280 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
281 endfunc
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
282
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
283 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
284 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
285 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
286 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
287 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
288 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
289 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
290 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
291 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
292 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
293 call assert_fails("call floor('')", 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
294 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
295
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
296 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
297 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
298 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
299 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
300 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
301 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
302 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
303 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
304 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
305 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
306 call assert_fails("call ceil('')", 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
307 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
308
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
309 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
310 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
311 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
312 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
313 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
314 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
315 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
316 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
317 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
318 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
319 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
320 call assert_fails("call round('')", 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
321 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
322
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 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
331 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
332 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
333 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
334 call assert_fails("call trunc('')", 'E808:')
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
335 endfunc
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
336
16213
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
337 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
338 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
339 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
340 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
341 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
342 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
343 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
344 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
345 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
346 endfunc
2c33b119ba92 patch 8.1.1111: it is not easy to check for infinity
Bram Moolenaar <Bram@vim.org>
parents: 11461
diff changeset
347
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 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
356 call assert_false(isnan({}))
10532
80b50e43e382 commit https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
357 endfunc
11461
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
358
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
359 " This was converted from test65
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
360 func Test_float_misc()
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
361 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
362 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
363 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
364 " +=
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
365 let v = 1.234
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
366 let v += 6.543
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
367 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
368 let v = 1.234
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
369 let v += 5
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
370 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
371 let v = 5
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
372 let v += 3.333
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
373 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
374 " ==
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
375 let v = 1.234
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
376 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
377 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
378 " add-subtract
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
379 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
380 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
381 " mult-div
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
382 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
383 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
384 " dict
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
385 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
386 " list
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
387 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
388 endfunc
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
389
5be73ebf6a15 patch 8.0.0614: float2nr() is not exactly right
Christian Brabandt <cb@256bit.org>
parents: 10557
diff changeset
390 " vim: shiftwidth=2 sts=2 expandtab