You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+62-51Lines changed: 62 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,57 +2,6 @@
2
2
3
3
Modular arithmetic for Julia.
4
4
5
-
## New in Version 2
6
-
7
-
8
-
9
-
With this new version the modulus of a `Mod` number must be of type `Int`.
10
-
If a `Mod` number is constructed with any other typeof `Integer`, the
11
-
constructor will (try to) convert it to type `Int`.
12
-
13
-
The old style `Mod{N,T}(v)` no longer works.
14
-
15
-
### Why this change?
16
-
17
-
There were various issues in the earlier version of `Mods` that are
18
-
resolved by requiring `N` to be of type `Int`.
19
-
20
-
* Previously `Mod` numbers created with different sorts of integer parameters would
21
-
be different. So if `N = 17` and `M = 0x11`, then `Mod{N}(1)` would not be interoperable with `Mod{M}(1).`
22
-
23
-
* The internal storage of the value of the `Mod` numbers could be different.
24
-
For example, `Mod{17}(-1)` would store the
25
-
value internally as `-1` whereas `Mod{17}(16)` would store the value as `16`.
26
-
27
-
* Finally, if the modulus were a large `Int128` number, then arithmetic
28
-
operations could silently fail.
29
-
30
-
We believe that the dominant use case for this module will be with moduli between
31
-
`2` and `2^63-1` and so we do not expect this change to affect
32
-
users. Further, since `Mod` numbers that required `Int128` moduli were
33
-
likely to give incorrect results, version 1 of this module was buggy.
34
-
35
-
Users who require *smaller* integer (e.g., `Int8`) types should use the latest version 1 of `Mods`.
36
-
37
-
> **NEW!** For small moduli (between 2 and 255) see the [MiniMods](https://github.com/scheinerman/MiniMods.jl) module.
38
-
39
-
In addition, some functionality has been moved to the `extras` folder.
40
-
See the `README` there.
41
-
42
-
### New in 2.2.3
43
-
44
-
The values of `Mod` numbers are held in 64-bit integers. If the moduli and values are
45
-
large enough, integer arithmetic might overflow and yield incorrect results. To deal
46
-
with this, integer values are expanded to 128 bits in order to ensure correctness,
47
-
and then reduced by the modulus.
48
-
49
-
In prior versions, we always expanded values to 128 bits before arithmetic.
50
-
51
-
Starting in version 2.2.3, expansion to 128 bits only happens for moduli above
52
-
`typemax(Int32)` which equals `2^31 - 1 = 2,147,483,647`. This results in a
53
-
roughly 4 or 5 times speedup compared to prior versions.
54
-
55
-
56
5
57
6
## Quick Overview
58
7
This module supports modular values and arithmetic. The moduli are integers (at least 2)
@@ -247,7 +196,11 @@ julia> value(a)
247
196
8
248
197
```
249
198
199
+
## Limitations
250
200
201
+
The modulus and value of a `Mod` number are of type `Int` (or `Complex{Int}` for `GaussMod` numbers). This implies that the largest possible modulus is `typemax(Int)` which equals `2^63-1`
202
+
(assuming a 64-bit system).
203
+
251
204
### Overflow safety
252
205
253
206
Integer operations on 64-bit numbers can give results requiring more than
@@ -270,6 +223,14 @@ julia> Mod{N}(a) * Mod{N}(a) # but this is correct!
270
223
Mod{1000000000000000000}(0)
271
224
```
272
225
226
+
This safety comes at a cost. If the modulus is large then operations may
227
+
require enlarging the values to 128-bits before reducing mod `N`. For multipication,
228
+
this widening occurs when the modulus exceeds `2^32-1`; for addition, widening occurs
0 commit comments