OSDN Git Service

【更新内容】
[ring-lang-081/ring.git] / docs / en / source / bignumber.txt
1 .. index:: 
2         single: bignumber; Introduction
3
4 =================
5 BigNumber Library
6 =================
7
8 In this chapter we will learn about using the Big Number library in the Ring programming language.
9
10 Developers : Bert Mariani, Gal Zsolt (~ CalmoSoft ~)
11
12 .. index:: 
13         pair: bignumber; Loading the library
14
15 Loading the library
16 ===================
17
18 Before using the next function load the bignumber.ring library
19
20 .. code-block:: ring
21
22         load "bignumber.ring"
23         # Use Big Number library functions
24
25 .. index:: 
26         pair: bignumber; Examples
27
28 Examples
29 ========
30
31 Using the BigNumber library we can do arithmetic operations on huge numbers.
32
33 Example:
34
35 .. code-block:: ring
36
37         load "bignumber.ring"
38
39         num1 = "62345678901234567891678345123456789"    ### Big
40         num2 =  "1237894567890123419871236545"          ### Small
41         num3 =     "64"                                 ### Divide Small
42         num4 = "765432"                 
43         num5 =      "3"                                 ### Power            
44     
45         ? "Add big numbers:" 
46         a1 = new BigNumber(num1)        a1.Print()
47         a2 = new BigNumber(num2)        a2.Print()
48         a3 = a1 + a2                    a3.Print() ? nl
49
50         ? "Substract big numbers:" 
51         a1 = new BigNumber(num1)        a1.Print()
52         a2 = new BigNumber(num2)        a2.Print()
53         a3 = a1 - a2                    a3.Print() ? nl
54
55         ? "Multiply big numbers:" 
56         a1 = new BigNumber(num1)        a1.print()
57         a2 = new BigNumber(num2)        a2.print()      
58         a3 = a1 * a2                    a3.print() ? nl
59
60         ? "Divide big numbers:" 
61         a1 = new BigNumber(num1)        a1.print()
62         a2 = new BigNumber(num2)        a2.print()
63         a3 = a1 / a2                    a3.print() ? nl
64     
65         ? "Divide big numbers: by very small number" 
66         a1 = new BigNumber(num1)        a1.print()
67         a2 = new BigNumber(num3)        a2.print()
68         a3 = a1 / a2                    a3.print() ? nl
69
70         ? "Power of big number:" 
71         a1 = new BigNumber(num1)        a1.print()
72         a2 = new BigNumber(num5)        a2.print()
73         a3 = a1 ^ a2                    a3.print() ? nl
74     
75 Output:
76
77 .. code-block:: none
78
79         Add big numbers:
80         62345678901234567891678345123456789
81         1237894567890123419871236545
82         62345680139129135781801764994693334
83
84
85         Substract big numbers:
86         62345678901234567891678345123456789
87         1237894567890123419871236545
88         52345687663340000001554925252220244
89
90
91         Multiply big numbers:
92         62345678901234567891678345123456789
93         1237894567890123419871236545
94         77177377243260150103462178714197454736432472780119682305154005
95
96
97         Divide big numbers:
98         62345678901234567891678345123456789
99         1237894567890123419871236545
100         50364288
101
102
103         Divide big numbers: by very small number
104         62345678901234567891678345123456789
105         64
106         974151232831790123307474142554012
107
108
109         Power of big number:
110         62345678901234567891678345123456789
111         3
112         242336636261471172092347146031727004 (Output continue in next line)
113         371698195628343934238988256152289508 (Output continue in next line)
114         493964611043228971692389860897069
115
116
117 .. index:: 
118         pair: bignumber; BigNumber Functions
119
120 BigNumber Functions
121 ===================
122
123 The library contains the next functions
124
125 .. code-block:: none
126
127         FuncAdd(num1,num2)
128         FuncSubtract(num1,num2)
129         FuncCompare(num1,num2)
130         FuncDivide(num1,num2)
131         FuncMultiply(num1,num2)
132         FuncPower(num1,num2)
133         FuncBinaryToDecimal(num1)
134         FuncDecimalToBinary(num1)
135         printBinaryDigits(binList)
136         printDecimalDigits(decList)
137
138 .. index:: 
139         pair: bignumber; BigNumber Class
140
141 BigNumber Class
142 ===============
143
144 The library contains the next class
145
146 .. code-block:: ring
147
148         class BigNumber 
149                 func init aPara 
150                 func operator cOperator, Para
151                 func print 
152                 func value
153
154 .. index:: 
155         pair: bignumber; Library Source Code 
156
157 Library Source Code
158 ===================
159
160 You can see the library source code in : ring/ringlibs/bignumber folder
161
162 Source Code : https://github.com/ring-lang/ring/blob/master/ringlibs/bignumber/bignumber.ring
163