big_pie 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7dd9cf921c6e24bfe1f748608efb699c76738cb545c5dc7bd0e9ce20092bf960
4
+ data.tar.gz: fdb96442e7ff23d4c0e9b05d04432a66803ee3afe779c0f82699eda281c6ef07
5
+ SHA512:
6
+ metadata.gz: 71da49e8bcbd3141151ff71881fca5b657d13bae8a2cff131e841af1570dc755b94a8b9a3119006921d4273f17cf87c9285a6509a0e09780603e60ca599315c5
7
+ data.tar.gz: d39ec351e98b839a6a1a766d6cd0c59d5a46764012456825236df41c020049720a5545ef2c1166044f1b6c7e7b8ce023e9531b0a99d27be435e1874c53c0b57b
data/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Sourav Goswami
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,115 @@
1
+ #include <gmp.h>
2
+ #include <inttypes.h>
3
+ #include "ruby.h"
4
+
5
+ #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
6
+ #pragma GCC optimize ("Ofast")
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
+ #endif
14
+
15
+ VALUE calculatePi(volatile VALUE obj, VALUE number) {
16
+ VALUE ary = rb_ary_new() ;
17
+ VALUE shove = rb_intern("<<") ;
18
+
19
+ uint64_t num = NUM2ULL(number) ;
20
+ uint64_t index = 0 ;
21
+ uint8_t comp ;
22
+
23
+ mpz_t q, t, k, m, x, r ;
24
+ mpz_t m_t ;
25
+ mpz_t temp1, temp2 ;
26
+
27
+ mpz_init(q) ;
28
+ mpz_init(t) ;
29
+ mpz_init(k) ;
30
+ mpz_init(m) ;
31
+ mpz_init(x) ;
32
+ mpz_init(r) ;
33
+ mpz_init(m_t) ;
34
+ mpz_init(temp1) ;
35
+ mpz_init(temp2) ;
36
+
37
+ mpz_set_ui(q, 1) ;
38
+ mpz_set_ui(t, 1) ;
39
+ mpz_set_ui(k, 1) ;
40
+ mpz_set_ui(m, 3) ;
41
+ mpz_set_ui(x, 3) ;
42
+ mpz_set_ui(r, 0) ;
43
+
44
+ while(index < num) {
45
+ mpz_mul_ui(temp1, q, 4) ;
46
+ mpz_add(temp1, temp1, r) ;
47
+ mpz_sub(temp1, temp1, t) ;
48
+ mpz_mul(m_t, m, t) ;
49
+
50
+ comp = mpz_cmp(m_t, temp1) ;
51
+ if(comp == 1) {
52
+ ++index ;
53
+ VALUE m_to_ui = INT2FIX(mpz_get_ui(m)) ;
54
+ rb_funcallv_public(ary, shove, 1, &m_to_ui) ;
55
+
56
+ //m
57
+ mpz_mul_ui(temp1, q, 3) ;
58
+ mpz_add(temp1, temp1, r) ;
59
+ mpz_mul_ui(temp1, temp1, 10) ;
60
+ mpz_tdiv_q(temp1, temp1, t) ;
61
+ mpz_mul_ui(temp2, m, 10) ;
62
+ mpz_sub(m, temp1, temp2) ;
63
+
64
+ // r
65
+ mpz_set(temp1, m_t) ;
66
+ mpz_sub(temp1, r, temp1) ;
67
+ mpz_mul_ui(r, temp1, 10) ;
68
+
69
+ //q
70
+ mpz_mul_ui(q, q, 10) ;
71
+ } else {
72
+ // t
73
+ mpz_mul(t, t, x) ;
74
+
75
+ // m
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) ;
81
+ mpz_tdiv_q(m, temp1, t) ;
82
+
83
+ // r
84
+ mpz_mul_ui(temp1, q, 2) ;
85
+ mpz_add(temp1, temp1, r) ;
86
+ mpz_mul(r, temp1, x) ;
87
+
88
+ // q
89
+ mpz_mul(q, q, k) ;
90
+
91
+ // k
92
+ mpz_add_ui(k, k, 1) ;
93
+
94
+ // x
95
+ mpz_add_ui(x, x, 2) ;
96
+ }
97
+ }
98
+
99
+ mpz_clear(q) ;
100
+ mpz_clear(t) ;
101
+ mpz_clear(k) ;
102
+ mpz_clear(m) ;
103
+ mpz_clear(x) ;
104
+ mpz_clear(r) ;
105
+ mpz_clear(m_t) ;
106
+ mpz_clear(temp1) ;
107
+ mpz_clear(temp2) ;
108
+
109
+ return ary ;
110
+ }
111
+
112
+ void Init_bigpie() {
113
+ VALUE _pi = rb_define_module("BigPie") ;
114
+ rb_define_module_function(_pi, "calculate", calculatePi, 1) ;
115
+ }
@@ -0,0 +1,9 @@
1
+ require 'mkmf'
2
+
3
+ abort "\e[38;2;255;255;0m\u2B21 You don't have gmp installed! Please follow the installation part on the documentation...\e[0m" unless have_header("gmp.h")
4
+
5
+ $CFLAGS = "-Ofast -fno-plt -march=native -mtune=native -lgmp"
6
+ puts "\e[1;38;2;255;80;80m\u2B22 CFLAGS: #{$CFLAGS}\e[0m"
7
+ puts "\e[1;38;2;80;80;255m\u2B22 LDFLAGS: #{$LDFLAGS}\e[0m"
8
+
9
+ create_makefile 'bigpie'
@@ -0,0 +1,4 @@
1
+ # Frozen_String_Literal: true
2
+
3
+ require 'bigpie'
4
+ require_relative "big_pie/version"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BigPie
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: big_pie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sourav Goswami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Calculate N Digits of Pi, argument upto unsigned long long (generally
14
+ 2 ** 64 - 1)
15
+ email:
16
+ - souravgoswami@protonmail.com
17
+ executables: []
18
+ extensions:
19
+ - ext/extconf.rb
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENCE
23
+ - ext/bigpie.c
24
+ - ext/extconf.rb
25
+ - lib/big_pie.rb
26
+ - lib/big_pie/version.rb
27
+ homepage: https://www.github.com/Souravgoswami/big_pie
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.1.0
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.1.4
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Calculate N Digits of Pi, argument upto unsigned long long (generally 2 **
50
+ 64 - 1)
51
+ test_files: []