Vim documentation: vital/Math
main help file
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
top - main help file - tag index