big_pie 0.1.0 → 0.1.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ext/bigpie.c +18 -22
  3. data/lib/big_pie/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dd9cf921c6e24bfe1f748608efb699c76738cb545c5dc7bd0e9ce20092bf960
4
- data.tar.gz: fdb96442e7ff23d4c0e9b05d04432a66803ee3afe779c0f82699eda281c6ef07
3
+ metadata.gz: 6f2443c252e9586a9483c60faa2d8b0e5f1bd7f991aae20784fbe23d9384d97d
4
+ data.tar.gz: 2f63619d9d059e4f3fc77f80a82eb0ad8455c4a26774e595b79070c62fd715fe
5
5
  SHA512:
6
- metadata.gz: 71da49e8bcbd3141151ff71881fca5b657d13bae8a2cff131e841af1570dc755b94a8b9a3119006921d4273f17cf87c9285a6509a0e09780603e60ca599315c5
7
- data.tar.gz: d39ec351e98b839a6a1a766d6cd0c59d5a46764012456825236df41c020049720a5545ef2c1166044f1b6c7e7b8ce023e9531b0a99d27be435e1874c53c0b57b
6
+ metadata.gz: 37a833f3a093ee4f8565f2dd0dd00d20b75d41135afeff2615e9ad78ca691595cc570996cb5e12570cba98b0a0cea7833c9e49542c3ce1c7379cf0505796300b
7
+ data.tar.gz: c10681865882155f1758ebdcd798248e498991e9022bc44c5e416f1596988433a2d51707c7c9265ed818c7213c393a4d5c7aaf23a7aed03891a383294433dcfb
@@ -16,13 +16,16 @@ VALUE calculatePi(volatile VALUE obj, VALUE number) {
16
16
  VALUE ary = rb_ary_new() ;
17
17
  VALUE shove = rb_intern("<<") ;
18
18
 
19
- uint64_t num = NUM2ULL(number) ;
20
- uint64_t index = 0 ;
21
- uint8_t comp ;
19
+ VALUE _rb_one = INT2FIX(0) ;
20
+ if (rb_funcallv_public(number, rb_intern("<"), 1, &_rb_one)) return ary ;
21
+
22
+ register uint64_t num = NUM2ULL(number) ;
23
+ register uint64_t index = 0 ;
24
+ register uint8_t comp ;
22
25
 
23
26
  mpz_t q, t, k, m, x, r ;
24
27
  mpz_t m_t ;
25
- mpz_t temp1, temp2 ;
28
+ mpz_t temp1 ;
26
29
 
27
30
  mpz_init(q) ;
28
31
  mpz_init(t) ;
@@ -32,7 +35,6 @@ VALUE calculatePi(volatile VALUE obj, VALUE number) {
32
35
  mpz_init(r) ;
33
36
  mpz_init(m_t) ;
34
37
  mpz_init(temp1) ;
35
- mpz_init(temp2) ;
36
38
 
37
39
  mpz_set_ui(q, 1) ;
38
40
  mpz_set_ui(t, 1) ;
@@ -42,8 +44,8 @@ VALUE calculatePi(volatile VALUE obj, VALUE number) {
42
44
  mpz_set_ui(r, 0) ;
43
45
 
44
46
  while(index < num) {
45
- mpz_mul_ui(temp1, q, 4) ;
46
- mpz_add(temp1, temp1, r) ;
47
+ mpz_set(temp1, r) ;
48
+ mpz_addmul_ui(temp1, q, 4) ;
47
49
  mpz_sub(temp1, temp1, t) ;
48
50
  mpz_mul(m_t, m, t) ;
49
51
 
@@ -55,16 +57,14 @@ VALUE calculatePi(volatile VALUE obj, VALUE number) {
55
57
 
56
58
  //m
57
59
  mpz_mul_ui(temp1, q, 3) ;
58
- mpz_add(temp1, temp1, r) ;
59
- mpz_mul_ui(temp1, temp1, 10) ;
60
+ mpz_addmul_ui(temp1, r, 10) ;
60
61
  mpz_tdiv_q(temp1, temp1, t) ;
61
- mpz_mul_ui(temp2, m, 10) ;
62
- mpz_sub(m, temp1, temp2) ;
62
+ mpz_submul_ui(temp1, m, 10) ;
63
+ mpz_set(m, temp1) ;
63
64
 
64
65
  // r
65
- mpz_set(temp1, m_t) ;
66
- mpz_sub(temp1, r, temp1) ;
67
- mpz_mul_ui(r, temp1, 10) ;
66
+ mpz_sub(r, r, m_t) ;
67
+ mpz_mul_ui(r, r, 10) ;
68
68
 
69
69
  //q
70
70
  mpz_mul_ui(q, q, 10) ;
@@ -74,16 +74,13 @@ VALUE calculatePi(volatile VALUE obj, VALUE number) {
74
74
 
75
75
  // m
76
76
  mpz_mul_ui(temp1, k, 7) ;
77
- mpz_add_ui(temp1, temp1, 2) ;
78
- mpz_mul(temp1, temp1, q) ;
79
- mpz_mul(temp2, r, x) ;
80
- mpz_add(temp1, temp1, temp2) ;
77
+ mpz_addmul_ui(temp1, q, 2) ;
78
+ mpz_addmul(temp1, r, x) ;
81
79
  mpz_tdiv_q(m, temp1, t) ;
82
80
 
83
81
  // r
84
- mpz_mul_ui(temp1, q, 2) ;
85
- mpz_add(temp1, temp1, r) ;
86
- mpz_mul(r, temp1, x) ;
82
+ mpz_addmul_ui(r, q, 2) ;
83
+ mpz_mul(r, r, x) ;
87
84
 
88
85
  // q
89
86
  mpz_mul(q, q, k) ;
@@ -104,7 +101,6 @@ VALUE calculatePi(volatile VALUE obj, VALUE number) {
104
101
  mpz_clear(r) ;
105
102
  mpz_clear(m_t) ;
106
103
  mpz_clear(temp1) ;
107
- mpz_clear(temp2) ;
108
104
 
109
105
  return ary ;
110
106
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BigPie
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big_pie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourav Goswami