ruby-mpfr 0.0.12 → 0.0.13
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.
- data/.gitignore +13 -0
- data/Gemfile +4 -0
- data/README.rdoc +8 -7
- data/Rakefile +26 -25
- data/ext/mpfr/ruby_mpfr.c +367 -219
- data/ext/mpfr_matrix/mpfr/func_mpfr_matrix.c +18 -21
- data/ext/mpfr_matrix/mpfr/ruby_mpfr_matrix.c +78 -62
- data/lib/mpfr/gmp.rb +1 -0
- data/lib/mpfr/matrix.rb +1 -0
- data/lib/mpfr/version.rb +3 -1
- data/ruby-mpfr.gemspec +19 -34
- data/spec/mpfr/comparison_spec.rb +59 -0
- data/spec/mpfr/conversion_spec.rb +174 -8
- metadata +53 -64
- data/.gemtest +0 -0
- data/Manifest.txt +0 -58
- data/PostInstall.txt +0 -7
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/tasks/extconf.rake +0 -36
data/lib/mpfr/gmp.rb
CHANGED
data/lib/mpfr/matrix.rb
CHANGED
data/lib/mpfr/version.rb
CHANGED
data/ruby-mpfr.gemspec
CHANGED
@@ -1,41 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mpfr/version"
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
|
-
s.name
|
5
|
-
s.version
|
6
|
+
s.name = "ruby-mpfr"
|
7
|
+
s.version = MPFR::VERSION
|
8
|
+
s.authors = ["Takayuki YAMAGUCHI"]
|
9
|
+
s.email = ["d@ytak.info"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = "Ruby bindings of MPFR"
|
12
|
+
s.description = "Ruby bindings of MPFR that is a C library for multiple-precision floating-point computations"
|
6
13
|
|
7
|
-
s.
|
8
|
-
s.authors = ["Takayuki YAMAGUCHI"]
|
9
|
-
s.date = %q{2009-12-26}
|
10
|
-
s.description = %q{ruby-mpfr is a library to use MPFR[http://www.mpfr.org/] which is a C library for
|
11
|
-
multiple-precision floating-point computations.
|
12
|
-
ruby-mpfr also includes Matrix class of MPFR; MPFR::Matrix, MPFR::SquareMatrix,
|
13
|
-
MPFR::ColumnVector, and MPFR::RowVector.
|
14
|
+
s.rubyforge_project = "ruby-mpfr"
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
s.
|
18
|
-
s.
|
19
|
-
s.
|
20
|
-
s.files = ["Example.rdoc", "History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "ext/mpfr/extconf.rb", "ext/mpfr/ruby_mpfr.c", "ext/mpfr/ruby_mpfr.h", "ext/mpfr_matrix/mpfr/extconf.rb", "ext/mpfr_matrix/mpfr/func_mpfr_matrix.c", "ext/mpfr_matrix/mpfr/func_mpfr_matrix.h", "ext/mpfr_matrix/mpfr/ruby_mpfr.h", "ext/mpfr_matrix/mpfr/ruby_mpfr_matrix.c", "ext/mpfr_matrix/mpfr/ruby_mpfr_matrix.h", "lib/mpfr/matrix.rb", "lib/mpfr/version.rb", "ruby-mpfr.gemspec", "script/console", "script/destroy", "script/generate", "spec/mpfr/allocate_spec.rb", "spec/mpfr/arithmetic_spec.rb", "spec/mpfr/comparison_spec.rb", "spec/mpfr/constant_spec.rb", "spec/mpfr/conversion_spec.rb", "spec/mpfr/exception_spec.rb", "spec/mpfr/functions_spec.rb", "spec/mpfr/generate_number_modulue.rb", "spec/mpfr/precision_roundmode_spec.rb", "spec/mpfr/rounding_spec.rb", "spec/mpfr/set_value_spec.rb", "spec/mpfr/spec_helper.rb", "spec/mpfr/string_spec.rb", "spec/mpfr_matrix/generate_matrix_arguments.rb", "spec/mpfr_matrix/mpfr_matrix_alloc_spec.rb", "spec/mpfr_matrix/mpfr_matrix_arithmetic_spec.rb", "spec/mpfr_matrix/mpfr_matrix_set_element_spec.rb", "spec/mpfr_matrix/mpfr_matrix_string_spec.rb", "spec/mpfr_matrix/mpfr_square_matrix_spec.rb", "spec/mpfr_matrix/spec_helper.rb", "spec/spec.opts", "tasks/extconf.rake"]
|
21
|
-
s.homepage = %q{http://rubyforge.org/projects/ruby-mpfr/}
|
22
|
-
s.post_install_message = %q{PostInstall.txt}
|
23
|
-
s.rdoc_options = ["--main", "README.rdoc"]
|
24
|
-
s.require_paths = ["lib", "ext"]
|
25
|
-
s.rubyforge_project = %q{ruby-mpfr}
|
26
|
-
s.rubygems_version = %q{1.3.5}
|
27
|
-
s.summary = %q{ruby-mpfr is a library to use MPFR[http://www.mpfr.org/] which is a C library for multiple-precision floating-point computations}
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib", "ext", "ext/gmp", "ext/mpfr_matrix"]
|
20
|
+
s.extensions = Dir.glob('ext/**/extconf.rb')
|
28
21
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
34
|
-
s.add_development_dependency(%q<hoe>, [">= 2.4.0"])
|
35
|
-
else
|
36
|
-
s.add_dependency(%q<hoe>, [">= 2.4.0"])
|
37
|
-
end
|
38
|
-
else
|
39
|
-
s.add_dependency(%q<hoe>, [">= 2.4.0"])
|
40
|
-
end
|
22
|
+
# specify any dependencies here; for example:
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "yard"
|
25
|
+
# s.add_runtime_dependency "rest-client"
|
41
26
|
end
|
@@ -19,3 +19,62 @@ describe MPFR, "when comparing two numbers" do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
describe MPFR do
|
23
|
+
context "checking whether number is nan" do
|
24
|
+
it "should return true" do
|
25
|
+
MPFR('nan').nan?.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return false" do
|
29
|
+
MPFR('1.23').nan?.should be_false
|
30
|
+
MPFR('inf').nan?.should be_false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "checking whether number is finite" do
|
35
|
+
it "should return true" do
|
36
|
+
MPFR('-0.28').finite?.should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return false" do
|
40
|
+
MPFR('nan').finite?.should be_false
|
41
|
+
MPFR('inf').finite?.should be_false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "checking whether number is zero" do
|
46
|
+
it "should return true" do
|
47
|
+
MPFR(0).zero?.should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return false" do
|
51
|
+
MPFR(1).zero?.should be_false
|
52
|
+
MPFR('nan').zero?.should be_false
|
53
|
+
MPFR('inf').zero?.should be_false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "checking whether number is nonzero" do
|
58
|
+
it "should return true" do
|
59
|
+
MPFR(1).nonzero?.should be_true
|
60
|
+
MPFR('nan').nonzero?.should be_true
|
61
|
+
MPFR('inf').nonzero?.should be_true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return false" do
|
65
|
+
MPFR(0).nonzero?.should be_false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "checking whether number is regular" do
|
70
|
+
it "should return true" do
|
71
|
+
MPFR(-1).regular?.should be_true
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return false" do
|
75
|
+
MPFR(0).regular?.should be_false
|
76
|
+
MPFR('nan').regular?.should be_false
|
77
|
+
MPFR('inf').regular?.should be_false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -1,14 +1,180 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
MPFR.set_default_prec(
|
3
|
+
MPFR.set_default_prec(256)
|
4
4
|
|
5
|
-
describe MPFR
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
describe MPFR do
|
6
|
+
context "when converting to float" do
|
7
|
+
it "should be transformed to float" do
|
8
|
+
num = GenerateNumber.float(1000, 100) + [0.0]
|
9
|
+
num.each do |a|
|
10
|
+
b = MPFR.new(a).get_d(MPFR::RNDZ)
|
11
|
+
a.should == b
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
|
-
end
|
14
15
|
|
16
|
+
context "when rounding" do
|
17
|
+
it "should round a positive number." do
|
18
|
+
a = MPFR('1.3')
|
19
|
+
a.round.should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should round a positive number to a bigger number." do
|
23
|
+
a = MPFR('1.5')
|
24
|
+
a.round.should == 2
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should round a negative number." do
|
28
|
+
a = MPFR('-1.3')
|
29
|
+
a.round.should == -1
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should round a negative number to a smaller number." do
|
33
|
+
a = MPFR('-1.5')
|
34
|
+
a.round.should == -2
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should round a big number." do
|
38
|
+
a = MPFR('1.3e+50')
|
39
|
+
a.round.should == 1.3e+50
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should raise MPFRDomainError." do
|
43
|
+
lambda do
|
44
|
+
MPFR.nan.round
|
45
|
+
end.should raise_error MPFRDomainError
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when flooring" do
|
50
|
+
it "should floor a positive number." do
|
51
|
+
a = MPFR('1.3')
|
52
|
+
a.floor.should == 1
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should floor a positive number to a bigger number." do
|
56
|
+
a = MPFR('1.5')
|
57
|
+
a.floor.should == 1
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should floor a negative number." do
|
61
|
+
a = MPFR('-1.3')
|
62
|
+
a.floor.should == -2
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should floor a negative number to a smaller number." do
|
66
|
+
a = MPFR('-1.5')
|
67
|
+
a.floor.should == -2
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should floor a big number." do
|
71
|
+
a = MPFR('1.3e+50')
|
72
|
+
a.floor.should == 1.3e+50
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should raise MPFRDomainError." do
|
76
|
+
lambda do
|
77
|
+
MPFR.nan.floor
|
78
|
+
end.should raise_error MPFRDomainError
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when ceiling" do
|
83
|
+
it "should ceil a positive number." do
|
84
|
+
a = MPFR('1.3')
|
85
|
+
a.ceil.should == 2
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should ceil a positive number to a bigger number." do
|
89
|
+
a = MPFR('1.5')
|
90
|
+
a.ceil.should == 2
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should ceil a negative number." do
|
94
|
+
a = MPFR('-1.3')
|
95
|
+
a.ceil.should == -1
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should ceil a negative number to a smaller number." do
|
99
|
+
a = MPFR('-1.5')
|
100
|
+
a.ceil.should == -1
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should ceil a big number." do
|
104
|
+
a = MPFR('1.3e+50')
|
105
|
+
a.ceil.should == 1.3e+50
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should raise MPFRDomainError." do
|
109
|
+
lambda do
|
110
|
+
MPFR.nan.ceil
|
111
|
+
end.should raise_error MPFRDomainError
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "when truncating" do
|
116
|
+
it "should truncate a positive number." do
|
117
|
+
a = MPFR('1.3')
|
118
|
+
a.truncate.should == 1
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should truncate a positive number to a bigger number." do
|
122
|
+
a = MPFR('1.5')
|
123
|
+
a.truncate.should == 1
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should truncate a negative number." do
|
127
|
+
a = MPFR('-1.3')
|
128
|
+
a.truncate.should == -1
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should truncate a negative number to a smaller number." do
|
132
|
+
a = MPFR('-1.5')
|
133
|
+
a.truncate.should == -1
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should truncate." do
|
137
|
+
a = MPFR('1.3e+50')
|
138
|
+
a.truncate.should == 1.3e+50
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should raise MPFRDomainError." do
|
142
|
+
lambda do
|
143
|
+
MPFR.nan.truncate
|
144
|
+
end.should raise_error MPFRDomainError
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when converting by to_i" do
|
149
|
+
it "should to_i a positive number." do
|
150
|
+
a = MPFR('1.3')
|
151
|
+
a.to_i.should == 1
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should to_i a positive number to a bigger number." do
|
155
|
+
a = MPFR('1.5')
|
156
|
+
a.to_i.should == 1
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should to_i a negative number." do
|
160
|
+
a = MPFR('-1.3')
|
161
|
+
a.to_i.should == -1
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should to_i a negative number to a smaller number." do
|
165
|
+
a = MPFR('-1.5')
|
166
|
+
a.to_i.should == -1
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should to_i." do
|
170
|
+
a = MPFR('1.3e+50')
|
171
|
+
a.to_i.should == 1.3e+50
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should raise MPFRDomainError." do
|
175
|
+
lambda do
|
176
|
+
MPFR.nan.to_i
|
177
|
+
end.should raise_error MPFRDomainError
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
metadata
CHANGED
@@ -1,56 +1,53 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mpfr
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.13
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.12
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Takayuki YAMAGUCHI
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
date: 2011-08-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &5605200 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
18
23
|
prerelease: false
|
19
|
-
|
24
|
+
version_requirements: *5605200
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
requirement: &5604680 !ruby/object:Gem::Requirement
|
20
28
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
25
33
|
type: :development
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
MPFR::ColumnVector, and MPFR::RowVector.
|
32
|
-
|
33
|
-
* History[link:History_txt.html]
|
34
|
-
* {Examples of Usage}[link:Example_rdoc.html]
|
35
|
-
email:
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *5604680
|
36
|
+
description: Ruby bindings of MPFR that is a C library for multiple-precision floating-point
|
37
|
+
computations
|
38
|
+
email:
|
36
39
|
- d@ytak.info
|
37
40
|
executables: []
|
38
|
-
|
39
|
-
extensions:
|
41
|
+
extensions:
|
40
42
|
- ext/mpfr/extconf.rb
|
41
|
-
- ext/mpfr_matrix/mpfr/extconf.rb
|
42
43
|
- ext/gmp/mpfr/extconf.rb
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
-
|
47
|
-
- README.rdoc
|
48
|
-
- Example.rdoc
|
49
|
-
files:
|
44
|
+
- ext/mpfr_matrix/mpfr/extconf.rb
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- .gitignore
|
50
48
|
- Example.rdoc
|
49
|
+
- Gemfile
|
51
50
|
- History.txt
|
52
|
-
- Manifest.txt
|
53
|
-
- PostInstall.txt
|
54
51
|
- README.rdoc
|
55
52
|
- Rakefile
|
56
53
|
- ext/gmp/mpfr/extconf.rb
|
@@ -76,9 +73,6 @@ files:
|
|
76
73
|
- lib/mpfr/rspec.rb
|
77
74
|
- lib/mpfr/version.rb
|
78
75
|
- ruby-mpfr.gemspec
|
79
|
-
- script/console
|
80
|
-
- script/destroy
|
81
|
-
- script/generate
|
82
76
|
- spec/gmp/convert_spec.rb
|
83
77
|
- spec/gmp/rand_spec.rb
|
84
78
|
- spec/gmp/spec_helper.rb
|
@@ -104,36 +98,31 @@ files:
|
|
104
98
|
- spec/mpfr_matrix/mpfr_matrix_string_spec.rb
|
105
99
|
- spec/mpfr_matrix/mpfr_square_matrix_spec.rb
|
106
100
|
- spec/mpfr_matrix/spec_helper.rb
|
107
|
-
|
108
|
-
- .gemtest
|
109
|
-
has_rdoc: true
|
110
|
-
homepage: http://rubyforge.org/projects/ruby-mpfr/
|
101
|
+
homepage: ''
|
111
102
|
licenses: []
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
- --main
|
116
|
-
- README.rdoc
|
117
|
-
require_paths:
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
118
106
|
- lib
|
119
|
-
|
107
|
+
- ext
|
108
|
+
- ext/gmp
|
109
|
+
- ext/mpfr_matrix
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
111
|
none: false
|
121
|
-
requirements:
|
122
|
-
- -
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version:
|
125
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
117
|
none: false
|
127
|
-
requirements:
|
128
|
-
- -
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version:
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
131
122
|
requirements: []
|
132
|
-
|
133
123
|
rubyforge_project: ruby-mpfr
|
134
|
-
rubygems_version: 1.5
|
124
|
+
rubygems_version: 1.8.5
|
135
125
|
signing_key:
|
136
126
|
specification_version: 3
|
137
|
-
summary:
|
127
|
+
summary: Ruby bindings of MPFR
|
138
128
|
test_files: []
|
139
|
-
|