big_pie 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/ext/bigpie.c +24 -19
- data/lib/big_pie.rb +0 -6
- data/lib/big_pie/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2db6a2fd68ee7adbf9929df4c4cf9097b6053230871d5a73f65733ac1c230e8d
|
|
4
|
+
data.tar.gz: c472cae6043e622789fe46d1a927c2da2fd0ea884b9dc115ac6fdd558d2b123a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d24697e37b8800e8607cfbd62811c21e56cc3ec994a37e45d1b15d50722df00fa9f83f964f29fe06c2610c787e48abd441c0cb1a7049c79e21a00ac9d58e1385
|
|
7
|
+
data.tar.gz: fed229285ca7eeaace2cc137003e3b8f3bbd7034909f4469e4350e44eccd5ae5351956cefe292d713aeffb6bbf4aba7bd7cc9473f8554712bac066d08c663646
|
data/ext/bigpie.c
CHANGED
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
#include <inttypes.h>
|
|
3
3
|
#include "ruby.h"
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
#ifdef __GNUC__
|
|
6
6
|
#pragma GCC optimize ("Ofast")
|
|
7
7
|
#pragma GCC diagnostic warning "-Wall"
|
|
8
|
-
#elif defined(__clang__)
|
|
9
|
-
#pragma clang optimize on
|
|
10
|
-
#pragma clang diagnostic warning "-Wall"
|
|
11
|
-
#elif defined(__INTEL_COMPILER)
|
|
12
|
-
#pragma intel optimization_level 3
|
|
13
8
|
#endif
|
|
14
9
|
|
|
15
10
|
VALUE calculatePi(volatile VALUE obj, volatile VALUE number) {
|
|
16
11
|
VALUE ary = rb_ary_new() ;
|
|
17
|
-
VALUE shove = rb_intern("<<") ;
|
|
18
|
-
|
|
19
12
|
VALUE _rb_one = INT2FIX(0) ;
|
|
20
|
-
|
|
13
|
+
VALUE block_given = rb_block_given_p() ;
|
|
14
|
+
|
|
15
|
+
if (rb_funcallv_public(number, rb_intern("<"), 1, &_rb_one)) {
|
|
16
|
+
if (block_given) {
|
|
17
|
+
return Qnil ;
|
|
18
|
+
} else {
|
|
19
|
+
return ary ;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
21
22
|
|
|
23
|
+
VALUE shove = rb_intern("<<") ;
|
|
22
24
|
register uint64_t num = NUM2ULL(number) ;
|
|
23
25
|
register uint64_t index = 0 ;
|
|
24
|
-
register int8_t comp ;
|
|
25
26
|
|
|
26
|
-
mpz_t q, t, k, m, x, r ;
|
|
27
|
-
mpz_t temp1 ;
|
|
27
|
+
mpz_t q, t, k, m, x, r, temp1 ;
|
|
28
28
|
|
|
29
29
|
mpz_init(q) ;
|
|
30
30
|
mpz_init(t) ;
|
|
@@ -46,14 +46,16 @@ VALUE calculatePi(volatile VALUE obj, volatile VALUE number) {
|
|
|
46
46
|
mpz_addmul_ui(temp1, q, 4) ;
|
|
47
47
|
mpz_submul(temp1, m, t) ;
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if(comp < 0) {
|
|
49
|
+
if(mpz_cmp_ui(temp1, 0) < 0) {
|
|
52
50
|
++index ;
|
|
53
51
|
VALUE m_to_ui = INT2FIX(mpz_get_ui(m)) ;
|
|
54
|
-
rb_funcallv_public(ary, shove, 1, &m_to_ui) ;
|
|
55
52
|
|
|
56
|
-
|
|
53
|
+
if (block_given) {
|
|
54
|
+
rb_yield_values(1, m_to_ui) ;
|
|
55
|
+
} else {
|
|
56
|
+
rb_funcallv_public(ary, shove, 1, &m_to_ui) ;
|
|
57
|
+
}
|
|
58
|
+
|
|
57
59
|
mpz_submul(r, m, t) ;
|
|
58
60
|
mpz_mul_ui(r, r, 10) ;
|
|
59
61
|
|
|
@@ -62,7 +64,6 @@ VALUE calculatePi(volatile VALUE obj, volatile VALUE number) {
|
|
|
62
64
|
} else {
|
|
63
65
|
mpz_mul(t, t, x) ;
|
|
64
66
|
|
|
65
|
-
// r
|
|
66
67
|
mpz_addmul_ui(r, q, 2) ;
|
|
67
68
|
mpz_mul(r, r, x) ;
|
|
68
69
|
|
|
@@ -81,7 +82,11 @@ VALUE calculatePi(volatile VALUE obj, volatile VALUE number) {
|
|
|
81
82
|
mpz_clear(r) ;
|
|
82
83
|
mpz_clear(temp1) ;
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
if (block_given) {
|
|
86
|
+
return Qnil ;
|
|
87
|
+
} else {
|
|
88
|
+
return ary ;
|
|
89
|
+
}
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
void Init_bigpie() {
|
data/lib/big_pie.rb
CHANGED
data/lib/big_pie/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: big_pie
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sourav Goswami
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-01-
|
|
11
|
+
date: 2021-01-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Calculate N Digits of Pi, argument upto unsigned long long (generally
|
|
14
14
|
2 ** 64 - 1)
|