basenumber 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: basenumber
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Package used for storing and performing arithmetic with integers of arbitrary base systems 2 and above.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Lightseeker7/basenumber
|
|
6
|
+
Author-email: "light.seeker" <light.the.seeker@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE.txt
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Requires-Dist: baseconvert
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# basenumber
|
|
16
|
+
Python library used for storing and performing arithmetic with integers of arbitrary base systems 2 and above.
|
|
17
|
+
|
|
18
|
+
Github: [link](https://github.com/Lightseeker7/basenumber)
|
|
19
|
+
# BaseNumber Objects
|
|
20
|
+
BaseNumber objects contain a tuple of integers for digits, an integer base, and a boolean for its negative state.
|
|
21
|
+
|
|
22
|
+
## Creation
|
|
23
|
+
To create a BaseNumber object using a tuple, it will set the object's value to the input tuple.
|
|
24
|
+
|
|
25
|
+
To create a BaseNumber object using an integer, it will first convert the integer into the appropriate tuple.
|
|
26
|
+
|
|
27
|
+
*The following two generate identical BaseNumber objects:*
|
|
28
|
+
```
|
|
29
|
+
BaseNumber(19,5)
|
|
30
|
+
```
|
|
31
|
+
```
|
|
32
|
+
BaseNumber((3,4),5)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The negative value is automatically set to false. To create a negative BaseNumber object, include it in the arguments.
|
|
36
|
+
```
|
|
37
|
+
BaseNumber((3,4),5,True)
|
|
38
|
+
```
|
|
39
|
+
```
|
|
40
|
+
BaseNumber((3,4),5,negative=True)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The instance variables holding these values are `value`, `base`, and `negative`.
|
|
44
|
+
|
|
45
|
+
## Operations
|
|
46
|
+
BaseNumber objects work with the following operations:
|
|
47
|
+
```
|
|
48
|
+
+ - * // % ** divmod()
|
|
49
|
+
```
|
|
50
|
+
These work with other BaseNumber objects, integers, and tuples of integers, and will return BaseNumber objects as outputs.
|
|
51
|
+
|
|
52
|
+
>Important
|
|
53
|
+
>>If you are trying to multiply extremely large numbers together, it is smart to use the `BaseNumber.karatsuba()` function, which `*` will call if it is above a certain threshold anyways.
|
|
54
|
+
|
|
55
|
+
Comparison operators also work with the same available objects:
|
|
56
|
+
```
|
|
57
|
+
< > == <= >=
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
They also work with the following functions:
|
|
61
|
+
```
|
|
62
|
+
int() float() abs() len() str()
|
|
63
|
+
```
|
|
64
|
+
`int()` will return the base 10 integer value of the number, `float()` the float of that number. `abs()` will set the `negative` value to `False`. `len()` will give the number of digits in the number.
|
|
65
|
+
|
|
66
|
+
`str` is represented with the value, base, and negative state:
|
|
67
|
+
```
|
|
68
|
+
(3, 12, 5) b13 negative:True
|
|
69
|
+
```
|
|
70
|
+
In the case of the value being too long or otherwise throwing an error, it will show only the first and last digits of the value:
|
|
71
|
+
```
|
|
72
|
+
(5 . . . 93) b104 negative:False
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Methods
|
|
76
|
+
You can call the following methods from the objects.
|
|
77
|
+
### convert()
|
|
78
|
+
```
|
|
79
|
+
convert(new_base)
|
|
80
|
+
```
|
|
81
|
+
This function will convert the value variable to a new base, set the base to the new base, and return itself.
|
|
82
|
+
### deep_convert()
|
|
83
|
+
```
|
|
84
|
+
deep_convert(new_base)
|
|
85
|
+
```
|
|
86
|
+
This function will create a new copy of the BaseNumber, convert it to a new base, and return the copy.
|
|
87
|
+
## Static Methods
|
|
88
|
+
The class has multiple static methods to call.
|
|
89
|
+
|
|
90
|
+
> Important
|
|
91
|
+
>>These static methods require the bases to be the same for them to function. The above operations (i.e. `*`, `+`, etc.) automatically convert the bases when called.
|
|
92
|
+
### try_convert()
|
|
93
|
+
```
|
|
94
|
+
BaseNumber.try_convert(num,i_base,b_base)
|
|
95
|
+
```
|
|
96
|
+
This will try to call `base()` from the `baseconvert` module, and upon failure will use a recursive process to do it more effectively
|
|
97
|
+
|
|
98
|
+
`num` is either a tuple or integer, `i_base` is the integer starting base and `b_base` is the new integer base.
|
|
99
|
+
### validate_bases()
|
|
100
|
+
```
|
|
101
|
+
BaseNumber.validate_bases(num1,num2)
|
|
102
|
+
```
|
|
103
|
+
This function will throw an error if either number is not a BaseNumber object, or if the bases are not the same.
|
|
104
|
+
### compare()
|
|
105
|
+
```
|
|
106
|
+
BaseNumber.compare(num1,num2)
|
|
107
|
+
```
|
|
108
|
+
Compares two BaseNumbers of the same base, will return a string of `"<"`, `">"`, or `"="` in relation to the comparative operator that matches `num1` and `num2`
|
|
109
|
+
### add()
|
|
110
|
+
```
|
|
111
|
+
BaseNumber.add(num1,num2)
|
|
112
|
+
```
|
|
113
|
+
This adds two BaseNumbers of the same base and returns a BaseNumber sum.
|
|
114
|
+
### subtract()
|
|
115
|
+
```
|
|
116
|
+
BaseNumber.subtract(num1,num2)
|
|
117
|
+
```
|
|
118
|
+
This subtracts two BaseNumbers of the same base (`num1 - num2`) and returns a BaseNumber output.
|
|
119
|
+
### multiply()
|
|
120
|
+
```
|
|
121
|
+
BaseNumber.multiply(num1,num2,allow_karatsuba=True)
|
|
122
|
+
```
|
|
123
|
+
Multiplies two BaseNumbers of the same base together.
|
|
124
|
+
|
|
125
|
+
If either value is greater than a certain threshold, it will call the `BaseNumber.karatsuba()` function to multiply the values together. (The threshold it checks against uses the class variable `KARATSUBA_THRESHOLD`, creates a base 10 number of that length in all `9`s, and checks if it is above that number. By default the variable is set to `30`)
|
|
126
|
+
|
|
127
|
+
If below the threshold , it attempts to convert both objects to integers, multiply them, then convert it back to the original value.
|
|
128
|
+
|
|
129
|
+
If either attempt fails or it is above the threshold and karatsuba is disabled, it will call the `BaseNumber.raw_multiply` function.
|
|
130
|
+
### raw_multiply
|
|
131
|
+
```
|
|
132
|
+
BaseNumber.raw_multiply(num1,num2)
|
|
133
|
+
```
|
|
134
|
+
Multiplies two BaseNumbers of the same base together using basic arithmetic. Longest form of multiplication.
|
|
135
|
+
### karatsuba()
|
|
136
|
+
```
|
|
137
|
+
BaseNumber.karatsuba(num1,num2)
|
|
138
|
+
```
|
|
139
|
+
Multiplies two BaseNumbers of the same base together using the karatsuba algorithm. Optimized for extremely long numbers, this function has succeeded at multiplying two numbers with 27,000+ digits each (although it takes exponentially longer. The multiplication of the two numbers with over 27,000 digits each took just over 3 hours to compute).
|
|
140
|
+
### exponent()
|
|
141
|
+
```
|
|
142
|
+
BaseNumber.raw_multiply(num,exponent)
|
|
143
|
+
```
|
|
144
|
+
Raises a BaseNumber to a BaseNumber exponent if both bases are the same.
|
|
145
|
+
### divmod()
|
|
146
|
+
```
|
|
147
|
+
BaseNumber.divmod(dividend,divisor)
|
|
148
|
+
```
|
|
149
|
+
Divides a BaseNumber dividend by a BaseNumber divisor if both bases are the same, returns a tuple of two BaseNumbers, the floored quotient and the modulus.
|
|
150
|
+
## Credit
|
|
151
|
+
This package would not be possible without squdle's `baseconvert` module at [baseconvert](https://pypi.org/project/baseconvert/).
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
basenumber-0.0.1.dist-info/METADATA,sha256=Dni4ZTOCGmd0X10ih_MVi_ktiERWEeFYc7t2D3QlsLc,5924
|
|
2
|
+
basenumber-0.0.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
3
|
+
basenumber-0.0.1.dist-info/licenses/LICENSE.txt,sha256=52RUi489Kdy5uQZw0gWZ6lJjaDlZjadj-b8nlL8OZ3c,1069
|
|
4
|
+
basenumber-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lightseeker7
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|