Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/ext/mod_int.h
8817 views
1
/* See mod_int.pxd if you want to use these declarations in Cython */
2
3
/* CPython using signed long as the data type for plain integers, which is
4
* - 8 bytes on 64-bit Linux and OSX
5
* - 4 bytes on 64-bit Windows and all 32-bit supported platforms.
6
* If you want to convert mod_int quickly to Python, then it must fit
7
* into such an integer. Otherwise you'll end up with Python's
8
* arbitrary-size integers instead of machine ints.
9
*
10
* However, 4 bytes is rather small and one can quickly run out of
11
* primes, especially if the problem has many bad primes. See Trac
12
* #10281 for details.
13
*
14
* Hence, we use signed 64-bit ints. This gives us fast conversion
15
* to/from Python on 64-bit Linux and OSX, and a large number of
16
* available (but not quite as fast) primes on 64-bit Windows and all
17
* 32-bit platforms (see Trac ##10281)
18
*/
19
#define mod_int int_fast64_t
20
21
/* The largest value we can do arithmetic on without risking overflowing.
22
* That is, you can multiply two MOD_INT_MAX in a mod_int.
23
*/
24
#define MOD_INT_OVERFLOW ((((mod_int)1) << (sizeof(mod_int)*8 - 1)) - 1)
25
#define MOD_INT_MAX ((mod_int)sqrt(MOD_INT_OVERFLOW) - 1)
26
27
28