-
Notifications
You must be signed in to change notification settings - Fork 64
/
Math.txt
132 lines (109 loc) · 3.47 KB
/
Math.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
*vital/Math.txt* Mathematical functions
Maintainer: ujihisa <ujihisa at gmail com>
==============================================================================
CONTENTS *Vital.Math-contents*
INTRODUCTION |Vital.Math-introduction|
INTERFACE |Vital.Math-interface|
FUNCTIONS |Vital.Math-functions|
==============================================================================
INTRODUCTION *Vital.Math-introduction*
*Vital.Math* provides some bitwise operators.
If vim provides builtin functions, uses these directly.
==============================================================================
INTERFACE *Vital.Math-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Math-functions*
fib({number}) *Vital.Math.fib()*
{number}th fib, begins with 0, 1.
>
fib(0) == 0
fib(1) == 1
fib(10) == 55
fib(48) == 512559680
fib(49) == -811192543
<
Note that Vim cannot handle big numbers. This is not
|Vital.Math.fib()|'s issue but Vim's limitation.
modulo({m}, {n}) *Vital.Math.modulo()*
Return modulo. This behaves like Scheme's one.
>
modulo(10, 3) == 1
modulo(-10, 3) == 2
modulo(10, -3) == -2
modulo(-10, -3) == -1
<
lcm({values}) *Vital.Math.lcm()*
Return least common multiple number of elements in {values}.
If at least one of {values} is 0, lcm returns 0.
>
lcm([2, 3]) == 6
lcm([2, -3]) == 6
lcm([7, 2, 3, 2]) == 42
lcm([0]) == 0
lcm([2, 3, 0]) == 0
<
gcd({values}) *Vital.Math.gcd()*
Return greatest common divisor of elements in {values}.
If all elements of {values} are 0, gcd returns 0.
If at least one of {values} is not 0, gcd returns greatest common
divisor of non zero elements.
>
gcd([2, 3]) == 1
gcd([20, -30]) == 10
gcd([5, 20, 30]) == 5
gcd([0]) == 0
gcd([4, 0, 6]) == 2
gcd([0, 0, 0]) == 0
<
sum({values}) *Vital.Math.sum()*
Return all sum of elements in {values}.
If {values} included not a number elements, throw an exception.
If {values} is empty list, returns 0.
>
sum([1, 2, 3, 4, 5]) == 15
sum([1, 2, 3.2, 4, 5.3]) == 15.5
sum([1, 2, '3', 4, 5]) " throw exception
sum([]) == 0
<
round({expr} [, {digits}]) *Vital.Math.round()*
Round off {expr} to {digits} digits after the decimal point and
return it as a Float.
If {digits} is omitted, it defaults to 0.
If {expr} lies halfway between two values, then use the larger
one (away from zero).
{expr} must evaluate to a Float or a Number.
>
round(2.675) == 3
round(2.675, 2) == 2.68
round(-2.675, 2) == -2.68
round(5.127, -1) == 10.0
round(5.127, 20) == 5.127
<
str2nr({expr} [, {base}]) *Vital.Math.str2nr()*
Convert string {expr} to a number.
{base} is the conversion base, it can be from 2 to 36.
When {base} is omitted base 10 is used. This also means that
a leading zero doesn't cause octal conversion to be used, as
with the default String to Number conversion.
[a-z] characters in {expr} are treated equally with [A-Z].
>
str2nr("10") == 10
str2nr("010") == 10
str2nr("10", 2) == 2
str2nr("FF", 16) == 255
str2nr("ZZ", 36) == 1295
str2nr("ff", 16) == 255
str2nr("Ff", 16) == 255
<
nr2str({expr} [, {base}]) *Vital.Math.nr2str()*
Convert number {expr} to string.
{base} is the conversion base, it can be from 2 to 36.
When {base} is omitted base 10 is used.
>
nr2str(10) == "10"
nr2str(10, 2) == "1010"
nr2str(255, 16) == "FF"
nr2str(1295, 36) == "ZZ"
<
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl