ruby-mpfr 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Example.rdoc +63 -0
- data/History.txt +6 -0
- data/Manifest.txt +1 -0
- data/README.rdoc +14 -9
- data/Rakefile +1 -0
- data/ext/mpfr/ruby_mpfr.c +1 -1
- data/lib/mpfr/version.rb +1 -1
- data/ruby-mpfr.gemspec +11 -8
- data/spec/mpfr/precision_roundmode_spec.rb +1 -0
- data/spec/mpfr_matrix/mpfr_matrix_arithmetic_spec.rb +2 -2
- metadata +9 -4
data/Example.rdoc
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
= Examples
|
2
|
+
|
3
|
+
== Example 1: Initialization
|
4
|
+
You must require 'mpfr' to use MPFR.
|
5
|
+
And you set the default precision by MPFR.set_default_prec.
|
6
|
+
To make an instance of MPFR, you can use MPFR.new or MPFR methods.
|
7
|
+
MPFR.new and MPFR have the same arguments.
|
8
|
+
First argument is a number which is Fixnum, Bignum, Float, String, or MPFR.
|
9
|
+
The following two optional arguments are rounding mode and precision.
|
10
|
+
|
11
|
+
require "mpfr"
|
12
|
+
MPFR.set_default_prec(100)
|
13
|
+
|
14
|
+
a = MPFR(3.3) # or MPFR.new(3.3)
|
15
|
+
b = MPFR('2.2') # or MPFR.new('2.2')
|
16
|
+
puts (a + b).to_s # => 5.4999999999999998223643160599724e+00
|
17
|
+
puts (a - b).to_s # => 1.0999999999999998223643160599743e+00
|
18
|
+
puts (a * b).to_s # => 7.2599999999999996092014953319487e+00
|
19
|
+
puts (a / b).to_s # => 1.4999999999999999192565072999879e+00
|
20
|
+
|
21
|
+
c = MPFR('4.321', MPFR::RNDU)
|
22
|
+
d = MPFR('4.321', MPFR::RNDD)
|
23
|
+
c > d # => true
|
24
|
+
|
25
|
+
e = MPFR('4.321', MPFR::RNDN, 256)
|
26
|
+
e.prec # => 256
|
27
|
+
d.prec # => 100
|
28
|
+
|
29
|
+
== Example 2: Convertion to String
|
30
|
+
You can use MPFR#to_s and MPFR#to_strf to convert
|
31
|
+
an instance of MPFR to String.
|
32
|
+
These methods use function mpfr_asprintf.
|
33
|
+
MPFR#to_s convert an instance to string by mpfr_asprintf(str, "%.Re", self);
|
34
|
+
If you execute MPFR#to_strf(format), you get string converted
|
35
|
+
by mpfr_asprintf(str, format, self);
|
36
|
+
|
37
|
+
require "mpfr"
|
38
|
+
MPFR.set_default_prec(128)
|
39
|
+
|
40
|
+
a = MPFR('0.3')
|
41
|
+
puts a.to_s # => 3.000000000000000000000000000000000000006e-01
|
42
|
+
puts a.to_strf("%.20Re") # => 3.00000000000000000000e-01
|
43
|
+
puts a.to_strf("%.20RE") # => 3.00000000000000000000E-01
|
44
|
+
puts a.to_strf("%.20Rf") # => 0.30000000000000000000
|
45
|
+
|
46
|
+
== Example 3: Special Functions
|
47
|
+
Special functions of MPFR is collected in MPFR::Math.
|
48
|
+
MPFR::Math.func corresponds to mpfr_func in C language.
|
49
|
+
For example, you can use MPFR::Math.log to use mpfr_log.
|
50
|
+
Method of MPFR::Math is two optional arguments; rounding mode and percision.
|
51
|
+
|
52
|
+
require "mpfr"
|
53
|
+
MPFR.set_default_prec(128)
|
54
|
+
|
55
|
+
MPFR::Math.log('0.3') # => -1.203972804325935992622746217761838502954e+00
|
56
|
+
MPFR::Math.sin(1.23) # => 9.424888019316975040865688397571963882576e-01
|
57
|
+
|
58
|
+
a = MPFR::Math.sin(1.23, MPFR::RNDU) # => 9.424888019316975040865688397571963882576e-01
|
59
|
+
b = MPFR::Math.sin(1.23, MPFR::RNDD) # => 9.424888019316975040865688397571963882547e-01
|
60
|
+
a > b # => true
|
61
|
+
|
62
|
+
e = MPFR::Math.sin(1.23, MPFR::RNDD, 256)
|
63
|
+
e.get_prec # => 256
|
data/History.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 0.0.6 2009-12-26
|
2
|
+
* 1 minor enhancement:
|
3
|
+
* Add documents of MPFR.
|
4
|
+
* 1 bug fix:
|
5
|
+
* MPFR.get_default_prec returns new default precision.
|
6
|
+
|
1
7
|
=== 0.0.5 2009-12-18
|
2
8
|
* 1 major enhancement:
|
3
9
|
* Add methods MPFR, MPFR::Matrix, MPFR::SquareMatrix, MPFR::ColumnVector, and MPFR::RowVector.
|
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -5,26 +5,22 @@
|
|
5
5
|
|
6
6
|
== Description:
|
7
7
|
|
8
|
-
ruby-mpfr is library to use MPFR[http://www.mpfr.org/] which is a C library for
|
8
|
+
ruby-mpfr is a library to use MPFR[http://www.mpfr.org/] which is a C library for
|
9
9
|
multiple-precision floating-point computations.
|
10
10
|
ruby-mpfr also includes Matrix class of MPFR; MPFR::Matrix, MPFR::SquareMatrix,
|
11
11
|
MPFR::ColumnVector, and MPFR::RowVector.
|
12
12
|
|
13
|
+
* History[link:History_txt.html]
|
14
|
+
* {Examples of Usage}[link:Example_rdoc.html]
|
15
|
+
|
13
16
|
== Notice:
|
14
17
|
|
15
18
|
* Many methods have not been tested sufficiently.
|
16
19
|
* Documentation is not complete.
|
17
20
|
|
18
|
-
== Example:
|
19
|
-
|
20
|
-
require "mpfr"
|
21
|
-
MPFR.get_default_prec(100)
|
22
|
-
a = MPFR.new(3)
|
23
|
-
b = MPFR.new('2.2')
|
24
|
-
puts (a * b).to_strf("%.30Re")
|
25
|
-
|
26
21
|
== Requirements:
|
27
22
|
|
23
|
+
* Ruby[http://www.ruby-lang.org/] 1.9.1 or later
|
28
24
|
* MPFR[http://www.mpfr.org/] 2.4.1 or later
|
29
25
|
|
30
26
|
For Ubuntu 9.10, we can install MPFR with the following command.
|
@@ -37,6 +33,15 @@ in the system satisfying the above requirements.
|
|
37
33
|
|
38
34
|
$ sudo gem install ruby-mpfr
|
39
35
|
|
36
|
+
== Related Software:
|
37
|
+
These two gem packages uses ruby-mpfr.
|
38
|
+
|
39
|
+
* ruby-mpc[http://gemcutter.org/gems/ruby-mpc/]: the arithmetic of complex numbers with multiprecision
|
40
|
+
* ruby-mpfi[http://gemcutter.org/gems/ruby-mpfi/]: the interval arithmetic with multiprecision
|
41
|
+
|
42
|
+
The following is an another multiple precision library which uses GMP.
|
43
|
+
* http://gemcutter.org/gems/gmp
|
44
|
+
|
40
45
|
== License:
|
41
46
|
|
42
47
|
ruby-mpfr
|
data/Rakefile
CHANGED
@@ -17,6 +17,7 @@ $hoe = Hoe.spec 'ruby-mpfr' do
|
|
17
17
|
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
18
18
|
self.spec_extras[:extensions] = ["ext/mpfr/extconf.rb", "ext/mpfr_matrix/mpfr/extconf.rb"]
|
19
19
|
self.extra_rdoc_files << 'README.rdoc'
|
20
|
+
self.extra_rdoc_files << 'Example.rdoc'
|
20
21
|
end
|
21
22
|
|
22
23
|
# require 'newgem/tasks'
|
data/ext/mpfr/ruby_mpfr.c
CHANGED
@@ -82,7 +82,7 @@ static VALUE r_mpfr_set_default_prec(VALUE self, VALUE prec)
|
|
82
82
|
rb_raise(rb_eRangeError, "Argument must be positive.");
|
83
83
|
}
|
84
84
|
mpfr_set_default_prec(set_prec);
|
85
|
-
return INT2FIX(
|
85
|
+
return INT2FIX(mpfr_get_default_prec());
|
86
86
|
}
|
87
87
|
|
88
88
|
/* Return the default MPFR precision in bits. */
|
data/lib/mpfr/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
RUBY_MPFR_VERSION = '0.0.
|
1
|
+
RUBY_MPFR_VERSION = '0.0.6'
|
data/ruby-mpfr.gemspec
CHANGED
@@ -2,26 +2,29 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ruby-mpfr}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.6"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Takayuki YAMAGUCHI"]
|
9
|
-
s.date = %q{2009-12-
|
10
|
-
s.description = %q{ruby-mpfr is library to use MPFR[http://www.mpfr.org/] which is a C library for
|
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
11
|
multiple-precision floating-point computations.
|
12
12
|
ruby-mpfr also includes Matrix class of MPFR; MPFR::Matrix, MPFR::SquareMatrix,
|
13
|
-
MPFR::ColumnVector, and MPFR::RowVector.
|
13
|
+
MPFR::ColumnVector, and MPFR::RowVector.
|
14
|
+
|
15
|
+
* History[link:History_txt.html]
|
16
|
+
* {Examples of Usage}[link:Example_rdoc.html]}
|
14
17
|
s.email = ["d@ytak.info"]
|
15
18
|
s.extensions = ["ext/mpfr/extconf.rb", "ext/mpfr_matrix/mpfr/extconf.rb"]
|
16
|
-
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
|
17
|
-
s.files = ["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"]
|
18
|
-
s.homepage = %q{
|
19
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Example.rdoc"]
|
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/}
|
19
22
|
s.post_install_message = %q{PostInstall.txt}
|
20
23
|
s.rdoc_options = ["--main", "README.rdoc"]
|
21
24
|
s.require_paths = ["lib", "ext"]
|
22
25
|
s.rubyforge_project = %q{ruby-mpfr}
|
23
26
|
s.rubygems_version = %q{1.3.5}
|
24
|
-
s.summary = %q{ruby-mpfr is library to use MPFR[http://www.mpfr.org/] which is a C library for multiple-precision floating-point computations}
|
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}
|
25
28
|
|
26
29
|
if s.respond_to? :specification_version then
|
27
30
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -37,9 +37,9 @@ describe MPFR::Matrix, "when arithmetic operator applies to 2x3 matrixies" do
|
|
37
37
|
it "should be subtracted" do
|
38
38
|
@args.each_index do |i|
|
39
39
|
if i > 0
|
40
|
-
res = @args[i-1]
|
40
|
+
res = @args[i-1] - @args[i]
|
41
41
|
(0...@row).each do |j|
|
42
|
-
(0...@column).each { |k| res[j, k].should eql(@args[i-1][j, k]
|
42
|
+
(0...@column).each { |k| res[j, k].should eql(@args[i-1][j, k] - @args[i][j, k]) }
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mpfr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takayuki YAMAGUCHI
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-26 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -23,10 +23,13 @@ dependencies:
|
|
23
23
|
version: 2.4.0
|
24
24
|
version:
|
25
25
|
description: |-
|
26
|
-
ruby-mpfr is library to use MPFR[http://www.mpfr.org/] which is a C library for
|
26
|
+
ruby-mpfr is a library to use MPFR[http://www.mpfr.org/] which is a C library for
|
27
27
|
multiple-precision floating-point computations.
|
28
28
|
ruby-mpfr also includes Matrix class of MPFR; MPFR::Matrix, MPFR::SquareMatrix,
|
29
29
|
MPFR::ColumnVector, and MPFR::RowVector.
|
30
|
+
|
31
|
+
* History[link:History_txt.html]
|
32
|
+
* {Examples of Usage}[link:Example_rdoc.html]
|
30
33
|
email:
|
31
34
|
- d@ytak.info
|
32
35
|
executables: []
|
@@ -39,7 +42,9 @@ extra_rdoc_files:
|
|
39
42
|
- Manifest.txt
|
40
43
|
- PostInstall.txt
|
41
44
|
- README.rdoc
|
45
|
+
- Example.rdoc
|
42
46
|
files:
|
47
|
+
- Example.rdoc
|
43
48
|
- History.txt
|
44
49
|
- Manifest.txt
|
45
50
|
- PostInstall.txt
|
@@ -111,6 +116,6 @@ rubyforge_project: ruby-mpfr
|
|
111
116
|
rubygems_version: 1.3.5
|
112
117
|
signing_key:
|
113
118
|
specification_version: 3
|
114
|
-
summary: ruby-mpfr is library to use MPFR[http://www.mpfr.org/] which is a C library for multiple-precision floating-point computations
|
119
|
+
summary: ruby-mpfr is a library to use MPFR[http://www.mpfr.org/] which is a C library for multiple-precision floating-point computations
|
115
120
|
test_files: []
|
116
121
|
|