daimyo-pi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +25 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/daimyo-pi.gemspec +24 -0
- data/lib/daimyo/pi.rb +37 -0
- data/lib/daimyo/pi/version.rb +5 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9961cc67833ce60d94631d6cc660e43949c96a282cc4688181072d1786b34a81
|
4
|
+
data.tar.gz: 996201da52d330701cfef9c166996514d764a4ebb5fbbf0515ad866627ae7ead
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be2260cf58f52e365a3bd9ce4e2c4d61dc822f40b21261f08cee3d101f60bc0252bf9344c4a67f95b6601f57df972546aefad2749b823092f8f62b6e86a338f3
|
7
|
+
data.tar.gz: ce63e5f1d09011ce87c8286e278368b22ce8aae4da5d82b80793a105f5555bf2aa235dec5c334b6defd825c8a261fb2e88037e8520a5e75d782ffe5c589b45b9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
daimyo-pi (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.3)
|
10
|
+
method_source (1.0.0)
|
11
|
+
pry (0.13.1)
|
12
|
+
coderay (~> 1.1)
|
13
|
+
method_source (~> 1.0)
|
14
|
+
rake (12.3.3)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
daimyo-pi!
|
21
|
+
pry
|
22
|
+
rake (~> 12.0)
|
23
|
+
|
24
|
+
BUNDLED WITH
|
25
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Daimyo::Pi
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/daimyo/pi`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'daimyo-pi'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install daimyo-pi
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/udzura/daimyo-pi.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "daimyo/pi"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/daimyo-pi.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'lib/daimyo/pi/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "daimyo-pi"
|
5
|
+
spec.version = Daimyo::Pi::VERSION
|
6
|
+
spec.authors = ["Uchio Kondo"]
|
7
|
+
spec.email = ["udzura@udzura.jp"]
|
8
|
+
|
9
|
+
spec.summary = %q{Calcurate PI}
|
10
|
+
spec.description = %q{Calcurate PI}
|
11
|
+
spec.homepage = "https://daimyo-college.pepabo.com/"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
# spec.add_dependency "faraday"
|
24
|
+
end
|
data/lib/daimyo/pi.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "daimyo/pi/version"
|
2
|
+
require "bigdecimal"
|
3
|
+
|
4
|
+
module Daimyo
|
5
|
+
class Pi
|
6
|
+
def initialize(precision: 10)
|
7
|
+
@precision = precision
|
8
|
+
end
|
9
|
+
attr_reader :precision
|
10
|
+
|
11
|
+
def leibniz(iter: 10)
|
12
|
+
ans = BigDecimal("0")
|
13
|
+
(0...iter).each do |n|
|
14
|
+
ans += (BigDecimal("-1") ** n) / (2 * n + 1)
|
15
|
+
end
|
16
|
+
|
17
|
+
return (ans * 4).truncate(precision)
|
18
|
+
end
|
19
|
+
|
20
|
+
def gauss_l(iter: 3)
|
21
|
+
a = BigDecimal("1")
|
22
|
+
b = BigDecimal("1") / BigDecimal("2").sqrt(precision)
|
23
|
+
t = BigDecimal("0.25")
|
24
|
+
p_ = BigDecimal("1")
|
25
|
+
|
26
|
+
iter.times do
|
27
|
+
an = (a + b) / 2
|
28
|
+
b = (a * b).sqrt(precision)
|
29
|
+
t -= p_ * (an - a) * (an - a)
|
30
|
+
p_ *= 2
|
31
|
+
a = an
|
32
|
+
end
|
33
|
+
|
34
|
+
((a + b) * (a + b) / (4 * t)).truncate(precision)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: daimyo-pi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Uchio Kondo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Calcurate PI
|
14
|
+
email:
|
15
|
+
- udzura@udzura.jp
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- bin/console
|
26
|
+
- bin/setup
|
27
|
+
- daimyo-pi.gemspec
|
28
|
+
- lib/daimyo/pi.rb
|
29
|
+
- lib/daimyo/pi/version.rb
|
30
|
+
homepage: https://daimyo-college.pepabo.com/
|
31
|
+
licenses: []
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 2.3.0
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubygems_version: 3.1.2
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Calcurate PI
|
52
|
+
test_files: []
|