-
Notifications
You must be signed in to change notification settings - Fork 64
/
BigNum.txt
81 lines (59 loc) · 2.43 KB
/
BigNum.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
*vital/Data/BigNum.txt* Multi precision integer library.
Maintainer: aomoriringo <sel0433 at gmail com>
==============================================================================
CONTENTS *Vital.Data.BigNum-contents*
INTRODUCTION |Vital.Data.BigNum-introduction|
INTERFACE |Vital.Data.BigNum-interface|
Functions |Vital.Data.BigNum-functions|
==============================================================================
INTRODUCTION *Vital.Data.BigNum-introduction*
*Vital.Data.BigNum* is a multi precision integer library.
It provides some functions to manipulate multi precision integer.
>
let s:V = vital#{plugin-name}#new()
let s:BigNum = s:V.import("Data.BigNum")
let x = s:BigNum.from_num(42)
let y = s:BigNum.from_string("12345678901")
let z = s:BigNum.add(x, y)
echo s:BigNum.to_string(z)
" 12345678943
let z = s:BigNum.mul(y, 9753)
echo s:BigNum.to_string(z)
" 120407406321453
let [div, mod] = s:BigNum.div_mod(y, "112233")
echo s:BigNum.to_string(div)
" 110000
echo s:BigNum.to_string(mod)
" 48901
<
==============================================================================
INTERFACE *Vital.Data.BigNum-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Data.BigNum-functions*
from_num({number}) *Vital.Data.BigNum.from_num()*
Return a new 'BigNum' object from {number}.
from_string({str}) *Vital.Data.BigNum.from_string()*
Return a new 'BigNum' object from {str}.
to_string({bignum}) *Vital.Data.BigNum.to_string()*
Return a string from {bignum}.
compare({elem1}, {elem2}) *Vital.Data.BigNum.compare()*
Compares as signed integer. Returns -1, 0, or 1.
add({elem1}, {elem2}) *Vital.Data.BigNum.add()*
Return {elem1} + {elem2}, for {elem1} and {elem2} Number, String or
BigNum.
sub({elem1}, {elem2}) *Vital.Data.BigNum.sub()*
Return {elem1} - {elem2}.
mul({elem1}, {elem2}) *Vital.Data.BigNum.mul()*
Return {elem1} * {elem2}.
div({elem1}, {elem2}) *Vital.Data.BigNum.div()*
Return {elem1} / {elem2}.
mod({elem1}, {elem2}) *Vital.Data.BigNum.mod()*
Return {elem1} % {elem2}.
div_mod({elem1}, {elem2}) *Vital.Data.BigNum.divmod()*
Return [Div(), Mod()].
sign({elem}) *Vital.Data.BigNum.sign()*
Return sign of {elem} as -1, 0, or 1.
neg({elem}) *Vital.Data.BigNum.neg()*
Return {elem} negated (-{elem}).
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl