ruby-mpfr 0.0.9 → 0.0.10
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/Manifest.txt +13 -0
- data/Rakefile +2 -1
- data/ext/gmp/mpfr/extconf.rb +21 -0
- data/ext/gmp/mpfr/gmp_header/gmpf.h +12 -0
- data/ext/gmp/mpfr/gmp_header/gmpq.h +12 -0
- data/ext/gmp/mpfr/gmp_header/gmpz.h +12 -0
- data/ext/gmp/mpfr/gmp_header/mprnd.h +12 -0
- data/ext/gmp/mpfr/gmp_header/ruby_gmp.h +385 -0
- data/ext/gmp/mpfr/gmp_header/takeover.h +36 -0
- data/ext/gmp/mpfr/ruby_mpfr_gmp.c +161 -0
- data/ext/gmp/mpfr/ruby_mpfr_gmp.h +14 -0
- data/ext/mpfr/ruby_mpfr.c +285 -84
- data/ext/mpfr/ruby_mpfr.h +1 -0
- data/lib/mpfr/gmp.rb +8 -0
- data/lib/mpfr/version.rb +1 -1
- data/spec/gmp/convert_spec.rb +43 -0
- data/spec/gmp/rand_spec.rb +22 -0
- data/spec/gmp/spec_helper.rb +14 -0
- data/spec/mpfr/functions_spec.rb +52 -0
- metadata +20 -6
data/ext/mpfr/ruby_mpfr.h
CHANGED
@@ -30,6 +30,7 @@ VALUE r_mpfr_make_new_fr_obj(MPFR *ptr);
|
|
30
30
|
VALUE r_mpfr_make_new_fr_obj2(MPFR *ptr, int prec);
|
31
31
|
VALUE r_mpfr_new_fr_obj(VALUE obj);
|
32
32
|
void r_mpfr_set_robj(MPFR *ptr, VALUE obj, mp_rnd_t rnd);
|
33
|
+
VALUE r_mpfr_robj_to_mpfr(VALUE obj, int argc, VALUE *argv);
|
33
34
|
|
34
35
|
mp_rnd_t r_mpfr_rnd_from_value(VALUE rnd);
|
35
36
|
mp_rnd_t r_mpfr_rnd_from_optional_argument(int min, int max, int argc, VALUE *argv);
|
data/lib/mpfr/gmp.rb
ADDED
data/lib/mpfr/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
RUBY_MPFR_VERSION = '0.0.
|
1
|
+
RUBY_MPFR_VERSION = '0.0.10'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe MPFR, "when converting to GMP." do
|
4
|
+
before(:all) do
|
5
|
+
@prec = 128
|
6
|
+
MPFR.set_default_prec(@prec)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return GMP::F objects" do
|
10
|
+
n = MPFR.new('1.234')
|
11
|
+
n.to_mpf.should be_an_instance_of GMP::F
|
12
|
+
n.to_mpf.should == GMP::F.new('1.234')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return GMP::F objects" do
|
16
|
+
n = MPFR.new('3.878')
|
17
|
+
n.to_mpz.should be_an_instance_of GMP::Z
|
18
|
+
n.to_mpz.should == GMP::Z.new(4)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe GMP, "when converting to MPFR." do
|
24
|
+
|
25
|
+
it "should return MPFR objects." do
|
26
|
+
n = GMP::F.new('-87.21')
|
27
|
+
n.to_fr.should be_an_instance_of MPFR
|
28
|
+
n.to_fr.should == MPFR.new('-87.21')
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe MPFR, "when converting by method MPFR." do
|
34
|
+
|
35
|
+
it "should return MPFR" do
|
36
|
+
n = GMP::F.new('0.0279')
|
37
|
+
MPFR(n).should be_an_instance_of MPFR
|
38
|
+
MPFR(n, 256).should be_an_instance_of MPFR
|
39
|
+
MPFR(n, :RNDD).should be_an_instance_of MPFR
|
40
|
+
MPFR(n, 512, :RNDU).should be_an_instance_of MPFR
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe MPFR, "when creating random number" do
|
4
|
+
before(:all) do
|
5
|
+
@prec = 200
|
6
|
+
MPFR.set_default_prec(@prec)
|
7
|
+
@creator = [GMP::RandState.new, GMP::RandState.new(:mt),
|
8
|
+
GMP::RandState.new(:lc_2exp, 3, 4, 10), GMP::RandState.new(:lc_2exp_size, 93)]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return MPFR objects" do
|
12
|
+
@creator.each do |c|
|
13
|
+
10.times do |i|
|
14
|
+
n = c.mpfr_urandomb2
|
15
|
+
n.should be_an_instance_of MPFR
|
16
|
+
n.should >= 0
|
17
|
+
n.should <= 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
begin
|
2
|
+
require 'rspec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
gem 'rspec'
|
6
|
+
require 'rspec'
|
7
|
+
end
|
8
|
+
|
9
|
+
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
10
|
+
$:.unshift(*Dir.glob(File.dirname(__FILE__) + '/../../ext/*'))
|
11
|
+
$:.unshift(File.dirname(__FILE__))
|
12
|
+
|
13
|
+
require 'mpfr'
|
14
|
+
require 'mpfr/gmp'
|
data/spec/mpfr/functions_spec.rb
CHANGED
@@ -20,6 +20,58 @@ describe MPFR, 'when executing mathematical functions' do
|
|
20
20
|
(Math::E - a).abs.should < error
|
21
21
|
(MPFR.new(1) - MPFR::Math.log(a)).abs.should < error
|
22
22
|
end
|
23
|
+
|
23
24
|
end
|
24
25
|
|
26
|
+
describe MPFR::Math do
|
27
|
+
context "when executing functions in MPFR::Math." do
|
28
|
+
it "should return MPFR" do
|
29
|
+
methods = [:const_log2, :const_pi, :const_euler, :const_catalan]
|
30
|
+
methods.each { |m| MPFR::Math.__send__(m).should be_an_instance_of MPFR }
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return MPFR from one arbitrary number." do
|
34
|
+
methods = [:sqr, :sqrt, :rec_sqrt, :cbrt,
|
35
|
+
:log, :log2, :log10, :exp, :exp2, :exp10,
|
36
|
+
:cos, :sin, :tan, :sec, :csc, :cot, :acos, :sin, :atan,
|
37
|
+
:cosh, :sinh, :tanh, :sech, :csch, :coth, :acosh, :asinh, :atanh,
|
38
|
+
:log1p, :expm1, :eint, :li2, :gamma, :lngamma, :digamma,
|
39
|
+
:zeta, :erf, :erfc, :j0, :j1, :y0, :y1, :ai]
|
40
|
+
[[MPFR('2.2379')]].each do |args|
|
41
|
+
methods.each { |m| MPFR::Math.__send__(m, *args).should be_an_instance_of MPFR }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return MPFR from one MPFR number and one positive integer." do
|
46
|
+
methods = [:mul_2si, :div_2si, :fac_ui,
|
47
|
+
:jn, :yn]
|
48
|
+
[[MPFR('2.2379'), 10]].each do |args|
|
49
|
+
methods.each { |m| MPFR::Math.__send__(m, *args).should be_an_instance_of MPFR }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return an array from one arbitrary number." do
|
54
|
+
methods = [:sin_cos, :sinh_cosh]
|
55
|
+
[[MPFR('2.2379')]].each do |args|
|
56
|
+
methods.each { |m| MPFR::Math.__send__(m, *args).should be_an_instance_of Array }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return MPFR from two arbitrary numbers." do
|
61
|
+
methods = [:add, :sub, :mul, :div, :pow, :dim,
|
62
|
+
:atan2, :agm, :hypot]
|
63
|
+
[[MPFR('10.287'), MPFR('3.827')]].each do |args|
|
64
|
+
methods.each { |m| MPFR::Math.__send__(m, *args).should be_an_instance_of MPFR }
|
65
|
+
end
|
66
|
+
end
|
25
67
|
|
68
|
+
it "should return MPFR from three arbitrary numbers." do
|
69
|
+
methods = [ :fma, :fms]
|
70
|
+
[[MPFR('2.199'), MPFR('7.83'), MPFR('5.28')]].each do |args|
|
71
|
+
methods.each { |m| MPFR::Math.__send__(m, *args).should be_an_instance_of MPFR }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 10
|
9
|
+
version: 0.0.10
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Takayuki YAMAGUCHI
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-21 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -42,9 +42,9 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
segments:
|
44
44
|
- 2
|
45
|
-
-
|
46
|
-
-
|
47
|
-
version: 2.
|
45
|
+
- 7
|
46
|
+
- 0
|
47
|
+
version: 2.7.0
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
50
|
description: |-
|
@@ -62,6 +62,7 @@ executables: []
|
|
62
62
|
extensions:
|
63
63
|
- ext/mpfr/extconf.rb
|
64
64
|
- ext/mpfr_matrix/mpfr/extconf.rb
|
65
|
+
- ext/gmp/mpfr/extconf.rb
|
65
66
|
extra_rdoc_files:
|
66
67
|
- History.txt
|
67
68
|
- Manifest.txt
|
@@ -75,6 +76,15 @@ files:
|
|
75
76
|
- PostInstall.txt
|
76
77
|
- README.rdoc
|
77
78
|
- Rakefile
|
79
|
+
- ext/gmp/mpfr/extconf.rb
|
80
|
+
- ext/gmp/mpfr/gmp_header/gmpf.h
|
81
|
+
- ext/gmp/mpfr/gmp_header/gmpq.h
|
82
|
+
- ext/gmp/mpfr/gmp_header/gmpz.h
|
83
|
+
- ext/gmp/mpfr/gmp_header/mprnd.h
|
84
|
+
- ext/gmp/mpfr/gmp_header/ruby_gmp.h
|
85
|
+
- ext/gmp/mpfr/gmp_header/takeover.h
|
86
|
+
- ext/gmp/mpfr/ruby_mpfr_gmp.c
|
87
|
+
- ext/gmp/mpfr/ruby_mpfr_gmp.h
|
78
88
|
- ext/mpfr/extconf.rb
|
79
89
|
- ext/mpfr/ruby_mpfr.c
|
80
90
|
- ext/mpfr/ruby_mpfr.h
|
@@ -84,12 +94,16 @@ files:
|
|
84
94
|
- ext/mpfr_matrix/mpfr/ruby_mpfr.h
|
85
95
|
- ext/mpfr_matrix/mpfr/ruby_mpfr_matrix.c
|
86
96
|
- ext/mpfr_matrix/mpfr/ruby_mpfr_matrix.h
|
97
|
+
- lib/mpfr/gmp.rb
|
87
98
|
- lib/mpfr/matrix.rb
|
88
99
|
- lib/mpfr/version.rb
|
89
100
|
- ruby-mpfr.gemspec
|
90
101
|
- script/console
|
91
102
|
- script/destroy
|
92
103
|
- script/generate
|
104
|
+
- spec/gmp/convert_spec.rb
|
105
|
+
- spec/gmp/rand_spec.rb
|
106
|
+
- spec/gmp/spec_helper.rb
|
93
107
|
- spec/mpfr/allocate_spec.rb
|
94
108
|
- spec/mpfr/arithmetic_spec.rb
|
95
109
|
- spec/mpfr/comparison_spec.rb
|