ruby-numtheory 0.0.8.1 → 0.0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/ext/numtheory/bignum.h +96 -0
- data/ext/numtheory/numtheory.c +8 -6
- data/ext/numtheory/numtheory.h +7 -0
- data/ruby-numtheory.gemspec +1 -1
- data/spec/numtheory/primality_tests_spec.rb +6 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5664624f001011ac200885754788be11cf9d987e
|
4
|
+
data.tar.gz: 677ca9f6744e113bbf8fee3e651adb55dabd37ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 039d5fb674c11e4b2f43f55801b1c0922ab542a4a4a3b8454488a7f536ec4f64264f0190a3cfb329ff19e171b17b5db84a460ae1134f714bb6c220f621c0bf83
|
7
|
+
data.tar.gz: 52d719becb03e7531fe445206e47681a0dead1e26a8f084a9f317a9526658cdbb09c8a9fbfbe742190915d3e36aa461feee7be722f5391cf1e3aca238b787701
|
data/.travis.yml
CHANGED
@@ -0,0 +1,96 @@
|
|
1
|
+
#ifndef NUMTHEORY_BIGNUM_H
|
2
|
+
#define NUMTHEORY_BIGNUM_H
|
3
|
+
|
4
|
+
#ifndef BDIGIT
|
5
|
+
# if SIZEOF_INT*2 <= SIZEOF_LONG_LONG
|
6
|
+
# define BDIGIT unsigned int
|
7
|
+
# define SIZEOF_BDIGIT SIZEOF_INT
|
8
|
+
# define BDIGIT_DBL unsigned LONG_LONG
|
9
|
+
# define BDIGIT_DBL_SIGNED LONG_LONG
|
10
|
+
# define PRI_BDIGIT_PREFIX ""
|
11
|
+
# define PRI_BDIGIT_DBL_PREFIX PRI_LL_PREFIX
|
12
|
+
# elif SIZEOF_INT*2 <= SIZEOF_LONG
|
13
|
+
# define BDIGIT unsigned int
|
14
|
+
# define SIZEOF_BDIGIT SIZEOF_INT
|
15
|
+
# define BDIGIT_DBL unsigned long
|
16
|
+
# define BDIGIT_DBL_SIGNED long
|
17
|
+
# define PRI_BDIGIT_PREFIX ""
|
18
|
+
# define PRI_BDIGIT_DBL_PREFIX "l"
|
19
|
+
# elif SIZEOF_SHORT*2 <= SIZEOF_LONG
|
20
|
+
# define BDIGIT unsigned short
|
21
|
+
# define SIZEOF_BDIGIT SIZEOF_SHORT
|
22
|
+
# define BDIGIT_DBL unsigned long
|
23
|
+
# define BDIGIT_DBL_SIGNED long
|
24
|
+
# define PRI_BDIGIT_PREFIX "h"
|
25
|
+
# define PRI_BDIGIT_DBL_PREFIX "l"
|
26
|
+
# else
|
27
|
+
# define BDIGIT unsigned short
|
28
|
+
# define SIZEOF_BDIGIT (SIZEOF_LONG/2)
|
29
|
+
# define SIZEOF_ACTUAL_BDIGIT SIZEOF_LONG
|
30
|
+
# define BDIGIT_DBL unsigned long
|
31
|
+
# define BDIGIT_DBL_SIGNED long
|
32
|
+
# define PRI_BDIGIT_PREFIX "h"
|
33
|
+
# define PRI_BDIGIT_DBL_PREFIX "l"
|
34
|
+
# endif
|
35
|
+
#endif
|
36
|
+
#ifndef SIZEOF_ACTUAL_BDIGIT
|
37
|
+
# define SIZEOF_ACTUAL_BDIGIT SIZEOF_BDIGIT
|
38
|
+
#endif
|
39
|
+
#ifdef PRI_BDIGIT_PREFIX
|
40
|
+
# define PRIdBDIGIT PRI_BDIGIT_PREFIX"d"
|
41
|
+
# define PRIiBDIGIT PRI_BDIGIT_PREFIX"i"
|
42
|
+
# define PRIoBDIGIT PRI_BDIGIT_PREFIX"o"
|
43
|
+
# define PRIuBDIGIT PRI_BDIGIT_PREFIX"u"
|
44
|
+
# define PRIxBDIGIT PRI_BDIGIT_PREFIX"x"
|
45
|
+
# define PRIXBDIGIT PRI_BDIGIT_PREFIX"X"
|
46
|
+
#endif
|
47
|
+
#ifdef PRI_BDIGIT_DBL_PREFIX
|
48
|
+
# define PRIdBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"d"
|
49
|
+
# define PRIiBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"i"
|
50
|
+
# define PRIoBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"o"
|
51
|
+
# define PRIuBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"u"
|
52
|
+
# define PRIxBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"x"
|
53
|
+
# define PRIXBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"X"
|
54
|
+
#endif
|
55
|
+
#define BIGNUM_EMBED_LEN_NUMBITS 3
|
56
|
+
#ifndef BIGNUM_EMBED_LEN_MAX
|
57
|
+
# if (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT) < (1 << BIGNUM_EMBED_LEN_NUMBITS)-1
|
58
|
+
# define BIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT)
|
59
|
+
# else
|
60
|
+
# define BIGNUM_EMBED_LEN_MAX ((1 << BIGNUM_EMBED_LEN_NUMBITS)-1)
|
61
|
+
# endif
|
62
|
+
#endif
|
63
|
+
|
64
|
+
#define SIZEOF_BDIGITS SIZEOF_BDIGIT
|
65
|
+
|
66
|
+
struct RBignum {
|
67
|
+
struct RBasic basic;
|
68
|
+
union {
|
69
|
+
struct {
|
70
|
+
size_t len;
|
71
|
+
BDIGIT *digits;
|
72
|
+
} heap;
|
73
|
+
BDIGIT ary[BIGNUM_EMBED_LEN_MAX];
|
74
|
+
} as;
|
75
|
+
};
|
76
|
+
|
77
|
+
#define RBIGNUM(obj) (R_CAST(RBignum)(obj))
|
78
|
+
#define BIGNUM_SIGN_BIT FL_USER1
|
79
|
+
#define RBIGNUM_SET_SIGN(b,sign) \
|
80
|
+
((sign) ? (RBASIC(b)->flags |= BIGNUM_SIGN_BIT) \
|
81
|
+
: (RBASIC(b)->flags &= ~BIGNUM_SIGN_BIT))
|
82
|
+
#define RBIGNUM_EMBED_FLAG FL_USER2
|
83
|
+
#define RBIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3)
|
84
|
+
#define RBIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+BIGNUM_EMBED_LEN_NUMBITS)
|
85
|
+
#define RBIGNUM_LEN(b) \
|
86
|
+
((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
|
87
|
+
(long)((RBASIC(b)->flags >> RBIGNUM_EMBED_LEN_SHIFT) & \
|
88
|
+
(RBIGNUM_EMBED_LEN_MASK >> RBIGNUM_EMBED_LEN_SHIFT)) : \
|
89
|
+
RBIGNUM(b)->as.heap.len)
|
90
|
+
/* LSB:BIGNUM_DIGITS(b)[0], MSB:BIGNUM_DIGITS(b)[BIGNUM_LEN(b)-1] */
|
91
|
+
#define RBIGNUM_DIGITS(b) \
|
92
|
+
((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
|
93
|
+
RBIGNUM(b)->as.ary : \
|
94
|
+
RBIGNUM(b)->as.heap.digits)
|
95
|
+
|
96
|
+
#endif
|
data/ext/numtheory/numtheory.c
CHANGED
@@ -69,6 +69,8 @@ Init_numtheory()
|
|
69
69
|
numtheory_fibonacci, -1);
|
70
70
|
rb_define_module_function(rb_mNumTheory, "precompute_primes_upto",
|
71
71
|
numtheory_precompute_primes_upto, 1);
|
72
|
+
rb_define_module_function(rb_mNumTheory, "primes_precomputed",
|
73
|
+
numtheory_primes_precomputed, 0);
|
72
74
|
rb_define_module_function(rb_mNumTheory, "prime",
|
73
75
|
numtheory_prime, 1);
|
74
76
|
rb_define_module_function(rb_mNumTheory, "primepi",
|
@@ -121,10 +123,12 @@ Init_numtheory()
|
|
121
123
|
numtheory_perfect_square_p, 0);
|
122
124
|
|
123
125
|
NUM_OF_PRIMES = init_sieve(PRIMES_UPPER_LIMIT);
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
126
|
+
}
|
127
|
+
|
128
|
+
VALUE
|
129
|
+
numtheory_primes_precomputed(VALUE obj)
|
130
|
+
{
|
131
|
+
return INT2FIX(NUM_OF_PRIMES);
|
128
132
|
}
|
129
133
|
|
130
134
|
/*
|
@@ -152,8 +156,6 @@ numtheory_precompute_primes_upto(VALUE obj, VALUE n)
|
|
152
156
|
free(numtheory_primes);
|
153
157
|
|
154
158
|
NUM_OF_PRIMES = init_sieve(PRIMES_UPPER_LIMIT);
|
155
|
-
rb_const_set(mNumTheory, rb_intern("PRECOMPUTED_PRIMES"),
|
156
|
-
INT2NUM(NUM_OF_PRIMES));
|
157
159
|
}
|
158
160
|
else
|
159
161
|
{
|
data/ext/numtheory/numtheory.h
CHANGED
@@ -10,10 +10,16 @@
|
|
10
10
|
#include <ruby/version.h>
|
11
11
|
#endif
|
12
12
|
|
13
|
+
#if RUBY_VERSION_MAJOR == 1
|
13
14
|
#if RUBY_VERSION_MINOR == 8
|
14
15
|
#include <intern.h>
|
15
16
|
#include <defines.h>
|
16
17
|
#endif
|
18
|
+
#elif RUBY_API_VERSION_MAJOR == 2
|
19
|
+
#if RUBY_API_VERSION_MINOR >= 2
|
20
|
+
#include "bignum.h"
|
21
|
+
#endif
|
22
|
+
#endif
|
17
23
|
|
18
24
|
#ifdef DEBUG
|
19
25
|
#include <stdio.h>
|
@@ -32,6 +38,7 @@ VALUE numtheory_powermod(int argc, VALUE *argv);
|
|
32
38
|
VALUE numtheory_miller_rabin_pseudoprime_p(VALUE n);
|
33
39
|
VALUE numtheory_nextprime(VALUE n);
|
34
40
|
VALUE numtheory_precompute_primes_upto(VALUE obj, VALUE n);
|
41
|
+
VALUE numtheory_primes_precomputed(VALUE obj);
|
35
42
|
VALUE numtheory_prime(VALUE obj, VALUE i);
|
36
43
|
VALUE numtheory_primepi(VALUE obj, VALUE n);
|
37
44
|
VALUE numtheory_fibonacci(int argc, VALUE *argv);
|
data/ruby-numtheory.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |gem|
|
|
3
3
|
gem.homepage = "http://github.com/lomereiter/ruby-numtheory"
|
4
4
|
gem.license = "MIT"
|
5
5
|
gem.summary = "Ruby number theory library"
|
6
|
-
gem.version = "0.0.
|
6
|
+
gem.version = "0.0.9.1"
|
7
7
|
gem.platform = Gem::Platform::RUBY
|
8
8
|
|
9
9
|
gem.description = <<-EOF
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-numtheory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Tarasov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
The library is written as C extension and aims to provide
|
@@ -22,11 +22,12 @@ extra_rdoc_files:
|
|
22
22
|
- ext/numtheory/numtheory.c
|
23
23
|
- LICENSE.txt
|
24
24
|
files:
|
25
|
-
- .travis.yml
|
25
|
+
- ".travis.yml"
|
26
26
|
- Gemfile
|
27
27
|
- LICENSE.txt
|
28
28
|
- README.md
|
29
29
|
- Rakefile
|
30
|
+
- ext/numtheory/bignum.h
|
30
31
|
- ext/numtheory/constants.h
|
31
32
|
- ext/numtheory/extconf.rb
|
32
33
|
- ext/numtheory/numtheory.c
|
@@ -53,17 +54,17 @@ require_paths:
|
|
53
54
|
- ext
|
54
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
56
|
requirements:
|
56
|
-
- -
|
57
|
+
- - ">="
|
57
58
|
- !ruby/object:Gem::Version
|
58
59
|
version: '0'
|
59
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
61
|
requirements:
|
61
|
-
- -
|
62
|
+
- - ">="
|
62
63
|
- !ruby/object:Gem::Version
|
63
64
|
version: '0'
|
64
65
|
requirements: []
|
65
66
|
rubyforge_project:
|
66
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.4.5
|
67
68
|
signing_key:
|
68
69
|
specification_version: 4
|
69
70
|
summary: Ruby number theory library
|