gnu_mpc 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/.yardopts +2 -0
- data/CHANGELOG +27 -5
- data/Gemfile +3 -1
- data/README.md +61 -5
- data/Rakefile +11 -3
- data/ext/extconf.rb +5 -1
- data/ext/gmprandstate.c +54 -0
- data/ext/mpc.c +358 -186
- data/ext/mpcrnd.c +3 -3
- data/ext/ruby_gmp.h +4 -4
- data/ext/ruby_mpc.h +2 -0
- data/manual.md +40 -14
- data/manual.pdf +0 -0
- data/spec/acos_spec.rb +15 -15
- data/spec/add_args_spec.rb +21 -21
- data/spec/add_fr_spec.rb +22 -22
- data/spec/add_spec.rb +12 -12
- data/spec/arg_spec.rb +14 -0
- data/spec/asin_spec.rb +12 -12
- data/spec/atan_spec.rb +26 -26
- data/spec/fma_spec.rb +20 -0
- data/spec/imag_spec.rb +23 -0
- data/spec/log10_spec.rb +21 -13
- data/spec/mpc_single_function_args_spec.rb +6 -6
- data/spec/new_spec.rb +54 -23
- data/spec/pow_spec.rb +79 -0
- data/spec/prec_arguments_spec.rb +40 -0
- data/spec/prec_spec.rb +17 -0
- data/spec/sub_spec.rb +35 -2
- data/spec/urandom_spec.rb +14 -0
- metadata +16 -5
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe MPC, "precision arguments" do
|
4
|
+
before do
|
5
|
+
@z = MPC.new([1.0, Math::PI])
|
6
|
+
end
|
7
|
+
|
8
|
+
it "accepts :prec and :precision" do
|
9
|
+
sqr = @z.sqr(prec: 32)
|
10
|
+
expect(sqr.real.prec).to eq 32
|
11
|
+
expect(sqr.imag.prec).to eq 32
|
12
|
+
|
13
|
+
sqr = @z.sqr(precision: 32)
|
14
|
+
expect(sqr.real.prec).to eq 32
|
15
|
+
expect(sqr.imag.prec).to eq 32
|
16
|
+
end
|
17
|
+
|
18
|
+
it "accepts :real_prec and :imag_prec" do
|
19
|
+
sqr = @z.sqr(imag_prec: 32)
|
20
|
+
expect(sqr.real.prec).to eq 53
|
21
|
+
expect(sqr.imag.prec).to eq 32
|
22
|
+
|
23
|
+
sqr = @z.sqr(real_prec: 64, imag_prec: 32)
|
24
|
+
expect(sqr.real.prec).to eq 64
|
25
|
+
expect(sqr.imag.prec).to eq 32
|
26
|
+
|
27
|
+
sqr = @z.sqr(real_precision: 64, imag_precision: 32)
|
28
|
+
expect(sqr.real.prec).to eq 64
|
29
|
+
expect(sqr.imag.prec).to eq 32
|
30
|
+
end
|
31
|
+
|
32
|
+
it "only accepts Fixnum for precision arguments" do
|
33
|
+
expect { @z.sqr(prec: 1.2) }.to raise_error(TypeError)
|
34
|
+
expect { @z.sqr(precision: 1.2) }.to raise_error(TypeError)
|
35
|
+
expect { @z.sqr(real_prec: 1.2) }.to raise_error(TypeError)
|
36
|
+
expect { @z.sqr(real_precision: 1.2) }.to raise_error(TypeError)
|
37
|
+
expect { @z.sqr(imag_prec: 1.2) }.to raise_error(TypeError)
|
38
|
+
expect { @z.sqr(imag_precision: 1.2) }.to raise_error(TypeError)
|
39
|
+
end
|
40
|
+
end
|
data/spec/prec_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe MPC, "precision arguments" do
|
4
|
+
before do
|
5
|
+
@z = MPC.new([1.0, Math::PI])
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns precision with :prec and :prec2" do
|
9
|
+
sqr = @z.sqr(prec: 32)
|
10
|
+
expect(sqr.prec).to eq 32
|
11
|
+
expect(sqr.prec2).to eq [32, 32]
|
12
|
+
|
13
|
+
sqr = @z.sqr(real_prec: 64, imag_prec: 32)
|
14
|
+
expect(sqr.prec).to eq 0
|
15
|
+
expect(sqr.prec2).to eq [64, 32]
|
16
|
+
end
|
17
|
+
end
|
data/spec/sub_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
2
2
|
|
3
3
|
# All tests adapted from MPC 1.0.1's tests/sub.dat
|
4
4
|
describe MPC, '#sub' do
|
5
|
-
it '
|
5
|
+
it 'calculates the difference between two real MPCs' do
|
6
6
|
op1 = MPC.new([GMP::F(1), GMP::F(0)])
|
7
7
|
op2 = MPC.new([GMP::F("0x1p-105", 53, 16), GMP::F(0)])
|
8
8
|
|
@@ -23,14 +23,16 @@ describe MPC, '#sub' do
|
|
23
23
|
actual.imag.should eq GMP::F(0)
|
24
24
|
end
|
25
25
|
|
26
|
-
it '
|
26
|
+
it 'calculates the difference between two a real and two imaginary MPCs' do
|
27
27
|
op1 = MPC.new([GMP::F(0), GMP::F("0x10000000000000p-106", 53, 16)])
|
28
28
|
op2 = MPC.new([0, 1])
|
29
|
+
|
29
30
|
actual = op1.sub(op2, MPC::MPC_RNDNN)
|
30
31
|
actual.real.should eq GMP::F(0)
|
31
32
|
actual.imag.should eq GMP::F("-0x10000000000000p-52", 53, 16)
|
32
33
|
|
33
34
|
op1 = MPC.new([GMP::F(0), GMP::F("0x10000000000001p-106", 53, 16)])
|
35
|
+
|
34
36
|
actual = op1.sub(op2, MPC::MPC_RNDNN)
|
35
37
|
actual.real.should eq GMP::F(0)
|
36
38
|
actual.imag.should eq GMP::F("-0x1fffffffffffffp-53", 53, 16)
|
@@ -48,3 +50,34 @@ describe MPC, '#sub' do
|
|
48
50
|
actual.imag.should eq GMP::F("-0x10000000000000p-52", 53, 16)
|
49
51
|
end
|
50
52
|
end
|
53
|
+
|
54
|
+
describe MPC, '#-' do
|
55
|
+
it 'calculates the difference between MPCs with #-' do
|
56
|
+
op1 = MPC.new([GMP::F(1), GMP::F(0)])
|
57
|
+
op2 = MPC.new([GMP::F("0x1p-105", 53, 16), GMP::F(0)])
|
58
|
+
|
59
|
+
actual = op1 - op2
|
60
|
+
expect(actual.real).to eq GMP::F("0x10000000000000p-52", 53, 16)
|
61
|
+
expect(actual.imag).to eq GMP::F(0)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe MPC, '#sub with more arguments' do
|
66
|
+
it 'calculates the difference between MPCs with a rounding mode and precision' do
|
67
|
+
op1 = MPC.new([GMP::F(1), GMP::F(0)])
|
68
|
+
op2 = MPC.new([GMP::F("0x1p-105", 53, 16), GMP::F(0)])
|
69
|
+
|
70
|
+
actual = op1.sub(op2, MPC::MPC_RNDNN, 32)
|
71
|
+
expect(actual.real).to eq GMP::F("0x10000000000000p-52", 32, 16)
|
72
|
+
expect(actual.imag).to eq GMP::F(0)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'calculates the difference between MPCs with a rounding mode and precision in a hash' do
|
76
|
+
op1 = MPC.new([GMP::F(1), GMP::F(0)])
|
77
|
+
op2 = MPC.new([GMP::F("0x1p-105", 53, 16), GMP::F(0)])
|
78
|
+
|
79
|
+
actual = op1.sub(op2, rounding_mode: MPC::MPC_RNDZZ, precision: 64)
|
80
|
+
expect(actual.real).to eq GMP::F("0x1fffffffffffffffep-65", 96, 16)
|
81
|
+
expect(actual.imag).to eq GMP::F(0)
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe "generating random complex numbers" do
|
4
|
+
it "generates random numbers inside the unit square" do
|
5
|
+
rs = GMP::RandState.new
|
6
|
+
10.times do
|
7
|
+
z = rs.mpc_urandom
|
8
|
+
expect(z.real).to be <= 1
|
9
|
+
expect(z.real).to be >= 0
|
10
|
+
expect(z.imag).to be <= 1
|
11
|
+
expect(z.imag).to be >= 0
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnu_mpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gmp
|
@@ -35,6 +35,7 @@ extensions:
|
|
35
35
|
- ext/extconf.rb
|
36
36
|
extra_rdoc_files: []
|
37
37
|
files:
|
38
|
+
- ext/gmprandstate.c
|
38
39
|
- ext/mpc.c
|
39
40
|
- ext/mpcrnd.c
|
40
41
|
- ext/ruby_gmp.h
|
@@ -45,18 +46,24 @@ files:
|
|
45
46
|
- spec/add_args_spec.rb
|
46
47
|
- spec/add_fr_spec.rb
|
47
48
|
- spec/add_spec.rb
|
49
|
+
- spec/arg_spec.rb
|
48
50
|
- spec/asin_spec.rb
|
49
51
|
- spec/atan_spec.rb
|
50
52
|
- spec/conj_spec.rb
|
51
53
|
- spec/cos_spec.rb
|
52
54
|
- spec/cosh_spec.rb
|
53
55
|
- spec/exp_spec.rb
|
56
|
+
- spec/fma_spec.rb
|
54
57
|
- spec/hash_arguments_spec.rb
|
58
|
+
- spec/imag_spec.rb
|
55
59
|
- spec/log10_spec.rb
|
56
60
|
- spec/log_spec.rb
|
57
61
|
- spec/mpc_single_function_args_spec.rb
|
58
62
|
- spec/neg_spec.rb
|
59
63
|
- spec/new_spec.rb
|
64
|
+
- spec/pow_spec.rb
|
65
|
+
- spec/prec_arguments_spec.rb
|
66
|
+
- spec/prec_spec.rb
|
60
67
|
- spec/proj_spec.rb
|
61
68
|
- spec/real_spec.rb
|
62
69
|
- spec/rounding_spec.rb
|
@@ -69,19 +76,23 @@ files:
|
|
69
76
|
- spec/tan_spec.rb
|
70
77
|
- spec/tanh_spec.rb
|
71
78
|
- spec/to_s_spec.rb
|
79
|
+
- spec/urandom_spec.rb
|
72
80
|
- spec/version_spec.rb
|
73
81
|
- README.md
|
74
82
|
- CHANGELOG
|
83
|
+
- COPYING.md
|
75
84
|
- manual.md
|
76
85
|
- manual.pdf
|
77
|
-
-
|
86
|
+
- manual_template.latex
|
78
87
|
- Makefile
|
79
88
|
- Rakefile
|
80
89
|
- Gemfile
|
81
90
|
- Guardfile
|
82
|
-
-
|
91
|
+
- .yardopts
|
92
|
+
- .rspec
|
83
93
|
homepage: http://github.com/srawlins/gnu_mpc
|
84
|
-
licenses:
|
94
|
+
licenses:
|
95
|
+
- Apache v2
|
85
96
|
post_install_message:
|
86
97
|
rdoc_options: []
|
87
98
|
require_paths:
|