gnu_mpc 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.md +13 -0
- data/Gemfile +17 -0
- data/Guardfile +18 -0
- data/Makefile +12 -0
- data/README.md +47 -0
- data/Rakefile +54 -0
- data/ext/extconf.rb +46 -0
- data/ext/mpc.c +1010 -0
- data/ext/mpcrnd.c +194 -0
- data/ext/ruby_gmp.h +343 -0
- data/ext/ruby_mpc.h +63 -0
- data/lib/mpc.rb +30 -0
- data/manual.md +933 -0
- data/manual.pdf +0 -0
- data/manual_template.latex +177 -0
- data/spec/acos_spec.rb +66 -0
- data/spec/add_args_spec.rb +51 -0
- data/spec/add_fr_spec.rb +54 -0
- data/spec/add_spec.rb +32 -0
- data/spec/asin_spec.rb +66 -0
- data/spec/atan_spec.rb +109 -0
- data/spec/conj_spec.rb +56 -0
- data/spec/cos_spec.rb +54 -0
- data/spec/cosh_spec.rb +26 -0
- data/spec/exp_spec.rb +62 -0
- data/spec/hash_arguments_spec.rb +17 -0
- data/spec/log_spec.rb +37 -0
- data/spec/mpc_single_function_args_spec.rb +41 -0
- data/spec/neg_spec.rb +30 -0
- data/spec/new_spec.rb +97 -0
- data/spec/proj_spec.rb +20 -0
- data/spec/real_spec.rb +23 -0
- data/spec/rounding_spec.rb +199 -0
- data/spec/sin_spec.rb +66 -0
- data/spec/sinh_spec.rb +65 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/sqr_spec.rb +96 -0
- data/spec/sqrt_spec.rb +72 -0
- data/spec/sub_spec.rb +50 -0
- data/spec/tan_spec.rb +55 -0
- data/spec/tanh_spec.rb +53 -0
- data/spec/to_s_spec.rb +77 -0
- data/spec/version_spec.rb +7 -0
- metadata +91 -0
data/spec/sqrt_spec.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
# All tests adapted from MPC 1.0.1's tests/sqrt.dat
|
4
|
+
describe MPC, '#sqrt' do
|
5
|
+
it 'should calculate the square root of a pure real number' do
|
6
|
+
data = [
|
7
|
+
[[ "0x16a09e667f3bcdp-52", 53, 16], [ 0, 53], MPC.new([GMP::F( 2, 53), GMP::F(0, 17)]), MPC::MPC_RNDNN],
|
8
|
+
[[ 0, 53], [ "0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(-2, 54), GMP::F(0, 16)]), MPC::MPC_RNDZN],
|
9
|
+
[[ "0x16a09e667f3bcdp-52", 53, 16], [ 0, 53], MPC.new([GMP::F( 2, 55), -GMP::F(0, 15)]), MPC::MPC_RNDUN],
|
10
|
+
[[ 0, 53], ["-0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(-2, 56), -GMP::F(0, 14)]), MPC::MPC_RNDDN],
|
11
|
+
[[ "0x5a827999fcef30p-54", 53, 16], [ 0, 53], MPC.new([GMP::F( 2, 57), GMP::F(0, 13)]), MPC::MPC_RNDZZ],
|
12
|
+
[[ 0, 53], [ "0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(-2, 58), GMP::F(0, 12)]), MPC::MPC_RNDUZ],
|
13
|
+
[[ "0x5a827999fcef30p-54", 53, 16], [ 0, 53], MPC.new([GMP::F( 2, 59), -GMP::F(0, 11)]), MPC::MPC_RNDDZ],
|
14
|
+
[[ 0, 53], ["-0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(-2, 60), -GMP::F(0, 10)]), MPC::MPC_RNDNZ],
|
15
|
+
[[ "0x16a09e667f3bcdp-52", 53, 16], [ 0, 53], MPC.new([GMP::F( 2, 61), GMP::F(0, 9)]), MPC::MPC_RNDUU],
|
16
|
+
[[ 0, 53], [ "0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(-2, 62), GMP::F(0, 8)]), MPC::MPC_RNDDU],
|
17
|
+
[[ "0x16a09e667f3bcdp-52", 53, 16], [ 0, 53], MPC.new([GMP::F( 2, 63), -GMP::F(0, 7)]), MPC::MPC_RNDNU],
|
18
|
+
[[ 0, 53], ["-0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(-2, 64), -GMP::F(0, 6)]), MPC::MPC_RNDZU],
|
19
|
+
[[ "0x5a827999fcef30p-54", 53, 16], [ 0, 53], MPC.new([GMP::F( 2, 65), GMP::F(0, 5)]), MPC::MPC_RNDDD],
|
20
|
+
[[ 0, 53], [ "0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(-2, 66), GMP::F(0, 4)]), MPC::MPC_RNDND],
|
21
|
+
[[ "0x5a827999fcef30p-54", 53, 16], [ 0, 53], MPC.new([GMP::F( 2, 67), -GMP::F(0, 3)]), MPC::MPC_RNDZD],
|
22
|
+
[[ 0, 53], ["-0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(-2, 68), -GMP::F(0, 2)]), MPC::MPC_RNDUD]
|
23
|
+
]
|
24
|
+
data.each do |expected_real, expected_imag, input, rounding_mode|
|
25
|
+
actual = input.sqrt(rounding_mode)
|
26
|
+
actual.real.should eq GMP::F.new(*expected_real)
|
27
|
+
actual.imag.should eq GMP::F.new(*expected_imag)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should calculate the square root of a pure imaginary number' do
|
32
|
+
data = [
|
33
|
+
[["0x16a09e667f3bcdp-52", 53, 16], [ "0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(0, 53), GMP::F( 4, 53, 16)]), MPC::MPC_RNDNN],
|
34
|
+
[["0x5a827999fcef30p-54", 53, 16], [ "0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(0, 51), GMP::F( 4, 54, 16)]), MPC::MPC_RNDZN],
|
35
|
+
[["0x16a09e667f3bcdp-52", 53, 16], ["-0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(0, 49), GMP::F(-4, 55, 16)]), MPC::MPC_RNDUN],
|
36
|
+
[["0x5a827999fcef30p-54", 53, 16], ["-0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(0, 47), GMP::F(-4, 56, 16)]), MPC::MPC_RNDDN],
|
37
|
+
[["0x5a827999fcef30p-54", 53, 16], [ "0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(0, 45), GMP::F( 4, 57, 16)]), MPC::MPC_RNDZZ],
|
38
|
+
[["0x16a09e667f3bcdp-52", 53, 16], [ "0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(0, 43), GMP::F( 4, 58, 16)]), MPC::MPC_RNDUZ],
|
39
|
+
[["0x5a827999fcef30p-54", 53, 16], ["-0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(0, 41), GMP::F(-4, 59, 16)]), MPC::MPC_RNDDZ],
|
40
|
+
[["0x16a09e667f3bcdp-52", 53, 16], ["-0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(0, 39), GMP::F(-4, 60, 16)]), MPC::MPC_RNDNZ],
|
41
|
+
[["0x16a09e667f3bcdp-52", 53, 16], [ "0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(0, 37), GMP::F( 4, 61, 16)]), MPC::MPC_RNDUU],
|
42
|
+
[["0x5a827999fcef30p-54", 53, 16], [ "0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(0, 35), GMP::F( 4, 62, 16)]), MPC::MPC_RNDDU],
|
43
|
+
[["0x16a09e667f3bcdp-52", 53, 16], ["-0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(0, 33), GMP::F(-4, 63, 16)]), MPC::MPC_RNDNU],
|
44
|
+
[["0x5a827999fcef30p-54", 53, 16], ["-0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(0, 31), GMP::F(-4, 64, 16)]), MPC::MPC_RNDZU],
|
45
|
+
[["0x5a827999fcef30p-54", 53, 16], [ "0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(0, 29), GMP::F( 4, 65, 16)]), MPC::MPC_RNDDD],
|
46
|
+
[["0x16a09e667f3bcdp-52", 53, 16], [ "0x5a827999fcef30p-54", 53, 16], MPC.new([GMP::F(0, 27), GMP::F( 4, 66, 16)]), MPC::MPC_RNDND],
|
47
|
+
[["0x5a827999fcef30p-54", 53, 16], ["-0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(0, 25), GMP::F(-4, 67, 16)]), MPC::MPC_RNDZD],
|
48
|
+
[["0x16a09e667f3bcdp-52", 53, 16], ["-0x16a09e667f3bcdp-52", 53, 16], MPC.new([GMP::F(0, 23), GMP::F(-4, 68, 16)]), MPC::MPC_RNDUD],
|
49
|
+
]
|
50
|
+
data.each do |expected_real, expected_imag, input, rounding_mode|
|
51
|
+
actual = input.sqrt(rounding_mode)
|
52
|
+
actual.real.should eq GMP::F.new(*expected_real)
|
53
|
+
actual.imag.should eq GMP::F.new(*expected_imag)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should calculate the square root of examples of bugs fixed in r160 2008-07-15' do
|
58
|
+
actual = MPC.new([GMP::F("0b1.101010001010100000p+117", 19, 2), GMP::F("-0b1.001110111101100001p-158", 19, 2)]).sqrt(MPC::MPC_RNDNZ, 19)
|
59
|
+
actual.real.should eq GMP::F( "0b11101001001001001100p+39", 19, 2)
|
60
|
+
actual.imag.should eq GMP::F("-0b1010110101100111011p-236", 19, 2)
|
61
|
+
|
62
|
+
actual = MPC.new([GMP::F(0, 2), GMP::F("-0b11p+203", 2, 2)]).sqrt(MPC::MPC_RNDNZ, 2)
|
63
|
+
actual.real.should eq GMP::F( "0b11p+100", 2, 2)
|
64
|
+
actual.imag.should eq GMP::F("-0b11p+100", 2, 2)
|
65
|
+
|
66
|
+
actual = MPC.new([GMP::F("-0b11p+235", 2, 2), -GMP::F(0, 2)]).sqrt(MPC::MPC_RNDNZ, 2)
|
67
|
+
actual.real.should eq GMP::F(0, 2)
|
68
|
+
actual.imag.should eq GMP::F("-0b10p+117", 2, 2)
|
69
|
+
end
|
70
|
+
|
71
|
+
### There are still more tests in sqrt.data, each a result of some bug or other thing
|
72
|
+
end
|
data/spec/sub_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
# All tests adapted from MPC 1.0.1's tests/sub.dat
|
4
|
+
describe MPC, '#sub' do
|
5
|
+
it 'should calculate the difference between two real MPCs' do
|
6
|
+
op1 = MPC.new([GMP::F(1), GMP::F(0)])
|
7
|
+
op2 = MPC.new([GMP::F("0x1p-105", 53, 16), GMP::F(0)])
|
8
|
+
|
9
|
+
actual = op1.sub(op2, MPC::MPC_RNDNN)
|
10
|
+
actual.real.should eq GMP::F("0x10000000000000p-52", 53, 16)
|
11
|
+
actual.imag.should eq GMP::F(0)
|
12
|
+
|
13
|
+
actual = op1.sub(op2, MPC::MPC_RNDZZ)
|
14
|
+
actual.real.should eq GMP::F("0x1fffffffffffffp-53", 53, 16)
|
15
|
+
actual.imag.should eq GMP::F(0)
|
16
|
+
|
17
|
+
actual = op1.sub(op2, MPC::MPC_RNDUU)
|
18
|
+
actual.real.should eq GMP::F("0x10000000000000p-52", 53, 16)
|
19
|
+
actual.imag.should eq GMP::F(0)
|
20
|
+
|
21
|
+
actual = op1.sub(op2, MPC::MPC_RNDDD)
|
22
|
+
actual.real.should eq GMP::F("0x1fffffffffffffp-53", 53, 16)
|
23
|
+
actual.imag.should eq GMP::F(0)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should calculate the difference between two a real and two imaginary MPCs' do
|
27
|
+
op1 = MPC.new([GMP::F(0), GMP::F("0x10000000000000p-106", 53, 16)])
|
28
|
+
op2 = MPC.new([0, 1])
|
29
|
+
actual = op1.sub(op2, MPC::MPC_RNDNN)
|
30
|
+
actual.real.should eq GMP::F(0)
|
31
|
+
actual.imag.should eq GMP::F("-0x10000000000000p-52", 53, 16)
|
32
|
+
|
33
|
+
op1 = MPC.new([GMP::F(0), GMP::F("0x10000000000001p-106", 53, 16)])
|
34
|
+
actual = op1.sub(op2, MPC::MPC_RNDNN)
|
35
|
+
actual.real.should eq GMP::F(0)
|
36
|
+
actual.imag.should eq GMP::F("-0x1fffffffffffffp-53", 53, 16)
|
37
|
+
|
38
|
+
actual = op1.sub(op2, MPC::MPC_RNDZZ)
|
39
|
+
actual.real.should eq GMP::F(0)
|
40
|
+
actual.imag.should eq GMP::F("-0x1fffffffffffffp-53", 53, 16)
|
41
|
+
|
42
|
+
actual = op1.sub(op2, MPC::MPC_RNDUU)
|
43
|
+
actual.real.should eq GMP::F(0)
|
44
|
+
actual.imag.should eq GMP::F("-0x1fffffffffffffp-53", 53, 16)
|
45
|
+
|
46
|
+
actual = op1.sub(op2, MPC::MPC_RNDDD)
|
47
|
+
actual.real.should eq GMP::F(0)
|
48
|
+
actual.imag.should eq GMP::F("-0x10000000000000p-52", 53, 16)
|
49
|
+
end
|
50
|
+
end
|
data/spec/tan_spec.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
# All tests adapted from MPC 1.0.1's tests/tan.dat
|
4
|
+
describe MPC, '#tan' do
|
5
|
+
it 'should calculate the tangent of huge values' do
|
6
|
+
data = [
|
7
|
+
[0, -1, MPC.new([GMP::F( "0x4580CBF242683p-3", 53, 16), GMP::F("-0x1B3E8A3660D279p-3", 53, 16)])],
|
8
|
+
[0, -1, MPC.new([GMP::F( "-0x4580CBF242683p-3", 53, 16), GMP::F("-0x1B3E8A3660D279p-3", 53, 16)])],
|
9
|
+
[0, 1, MPC.new([GMP::F("-0x1B3E8A3660D279p-3", 53, 16), GMP::F( "0x4580CBF242683p-3", 53, 16)])]
|
10
|
+
]
|
11
|
+
data.each do |expected_real, expected_imag, input|
|
12
|
+
actual = input.tan
|
13
|
+
actual.real.should eq GMP::F.new(expected_real)
|
14
|
+
actual.imag.should eq GMP::F.new(expected_imag)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should calculate the tangent of some values taken from ttan.c' do
|
19
|
+
data = [
|
20
|
+
[["0x1D02967C31CDB5", 53, 16], ["0x1D02967C31CDB5", 53, 16], ["0x3243F6A8885A30p-53", 53, 16], ["0x11A62633145C07p-106", 53, 16], MPC::MPC_RNDNN],
|
21
|
+
[["0x1D02967C31CDB4", 53, 16], ["0x1D02967C31CDB5", 53, 16], ["0x3243F6A8885A30p-53", 53, 16], ["0x11A62633145C07p-106", 53, 16], MPC::MPC_RNDDU],
|
22
|
+
[["0x1D02967C31CDB4", 53, 16], ["0x1D02967C31CDB4", 53, 16], ["0x3243F6A8885A30p-53", 53, 16], ["0x11A62633145C07p-106", 53, 16], MPC::MPC_RNDZD],
|
23
|
+
[["-0xB0BD0AA4A3B3D", 53, 16], ["-0xB0BD0AA4A3B3D", 53, 16], ["0x1921FB54442D19p-52", 53, 16], ["-0x172CECE675D1FDp-105", 53, 16], MPC::MPC_RNDNN],
|
24
|
+
]
|
25
|
+
data.each do |expected_real, expected_imag, input_real, input_imag, rounding_mode|
|
26
|
+
actual = MPC.new([GMP::F.new(*input_real), GMP::F.new(*input_imag)]).tan(rounding_mode)
|
27
|
+
actual.real.should eq GMP::F.new(*expected_real)
|
28
|
+
actual.imag.should eq GMP::F.new(*expected_imag)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should calculate the tangent of a corner case: op = atan (2^(-k) + i*2^k) for k=200 and k=1000' do
|
33
|
+
input_real = GMP::F.new("0x1.921fb54442d18469898cc51701b839a252049c1114cf98e804177d4c76273644a29410f31c6809bbdf2a33679a748636605614dbe4be286e9fc26adadaa3848bc90b6aecc4bcfd8de89884d34c6fdad617feb96de80d6fdbdc70d7f6b5133f4b5d3e4822f8963fcc9250cca3d9c8b67b8400f97142c77e0b31b4906c38", 1000, 16)
|
34
|
+
input_imag = GMP::F.new("0x1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000055555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555548888888888888888888888888888888888888888888888888a@-50", 1000, 16)
|
35
|
+
actual = MPC.new([input_real, input_imag], 1000).tan(MPC::MPC_RNDNN, 100, 100)
|
36
|
+
actual.real.should eq GMP::F.new("0x1@-50", 100, 16)
|
37
|
+
actual.imag.should eq GMP::F.new("0x1@50", 100, 16)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should calculate the tangent of a corner case: op = atan (2^(-k) + i*2^k) for k=200 and k=1000' do
|
41
|
+
input_real = GMP::F.new("0x1.921fb54442d18469898cc51701b839a252049c1114cf98e804177d4c76273644a29410f31c6809bbdf2a33679a748636605614dbe4be286e9fc26adadaa3848bc90b6aecc4bcfd8de89885d34c6fdad617feb96de80d6fdbdc70d7f6b5133f4b5d3e4822f8963fcc9250cca3d9c8b67b8400f97142c77e0b31b4906c38aba734d22c7f51fa499ebf06caba47b9475b2c38c5e6ac410aa5773daa520ee12d2cdace186a9c95793009e2e8d811943042f86520bc8c5c6d9c77c73cee58301d0c07364f0745d80f451f6b8abbe0de98a593bc5797ed2ab02e30732a92f9d52ad5ca2ba44c3131f40a202ae51cb51555885b5a662e1a08a0f46750aa4357be3974c9d9f70a08b1b7de1515d4e2aeba0c18fb672e1f0b4dc3c98f57eb5d19b61267ae3d1929c0944ac33b9dc7a44c35a5dcd7e25ff40db31410c9b0ec04e67d90d4c8a43e56302ef6401977c22eaef4c2bad8ee13118175b28dc411c49f40e9cb566287b6b7f9c1fa211c9705a2415242100234e478254f0fccaf10e334217b74b64d33864e30d5e9c4783528d0696c2a17b44b07d39455a899d1b77785b609bd1df25d1df8283f7d954c50f8b28e9cd780bb33652c9f412187444677430ca2b7cfda3ec252e19dc5af5f7037baec42e09039a00d224fab60b5532769d5311b1fbb830dff6fb9214d811e9be86b92680509246d87f56a", 4000, 16)
|
42
|
+
input_imag = GMP::F.new("0x1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000055555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556@-250", 4000, 16)
|
43
|
+
actual = MPC.new([input_real, input_imag], 4000).tan(MPC::MPC_RNDNN, 100, 100)
|
44
|
+
actual.real.should eq GMP::F.new("0x1@-250", 100, 16)
|
45
|
+
actual.imag.should eq GMP::F.new("0x1@250", 100, 16)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should calculate the tangent of a corner case' do
|
49
|
+
input_real = GMP::F.new("-0x16dp-8", 9, 16)
|
50
|
+
input_imag = GMP::F.new("-0x77p-3", 9, 16)
|
51
|
+
actual = MPC.new([input_real, input_imag], 9).tan(MPC::MPC_RNDNN, 9, 9)
|
52
|
+
actual.real.should eq GMP::F.new("-0x9bp-51", 9, 16)
|
53
|
+
actual.imag.should eq GMP::F.new(-1, 9)
|
54
|
+
end
|
55
|
+
end
|
data/spec/tanh_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
# All tests adapted from MPC 1.0.1's tests/tanh.dat
|
4
|
+
describe MPC, '#tanh' do
|
5
|
+
it 'should calculate the hyperbolic tangent of a pure real argument' do
|
6
|
+
data = [
|
7
|
+
["-0xc2f7d5a8a79ccp-52", MPC.new([GMP::F(-1, 7), GMP::F(0, 7)])],
|
8
|
+
[ "0xc2f7d5a8a79ccp-52", MPC.new([GMP::F( 1, 7), GMP::F(0, 7)])]
|
9
|
+
]
|
10
|
+
data.each do |expected, input|
|
11
|
+
actual = input.tanh(MPC::MPC_RNDNN, 50, 50)
|
12
|
+
actual.real.should eq GMP::F.new(expected, 50, 16)
|
13
|
+
actual.imag.should eq GMP::F(0)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should calculate the hyperbolic tangent of a pure imaginary argument' do
|
18
|
+
data = [
|
19
|
+
["-0x18eb245cbee3a8p-52", MPC.new([GMP::F(0, 7), GMP::F(-1, 7)])],
|
20
|
+
[ "0x18eb245cbee3a8p-52", MPC.new([GMP::F(0, 7), GMP::F( 1, 7)])]
|
21
|
+
]
|
22
|
+
data.each do |expected, input|
|
23
|
+
actual = input.tanh(MPC::MPC_RNDNN, 50, 50)
|
24
|
+
actual.real.should eq GMP::F(0)
|
25
|
+
actual.imag.should eq GMP::F.new(expected, 50, 16)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should calculate the hyperbolic tangent of an argument with +1 and -1' do
|
30
|
+
data = [
|
31
|
+
["-0x1157bffca4a8cp-48", "-0x459193d28cfe2p-52", MPC.new([GMP::F(-1, 7), GMP::F(-1, 7)])],
|
32
|
+
["-0x1157bffca4a8cp-48", "0x459193d28cfe2p-52", MPC.new([GMP::F(-1, 7), GMP::F( 1, 7)])],
|
33
|
+
[ "0x1157bffca4a8cp-48", "-0x459193d28cfe2p-52", MPC.new([GMP::F( 1, 7), GMP::F(-1, 7)])],
|
34
|
+
[ "0x1157bffca4a8cp-48", "0x459193d28cfe2p-52", MPC.new([GMP::F( 1, 7), GMP::F( 1, 7)])]
|
35
|
+
]
|
36
|
+
data.each do |expected_real, expected_imag, input|
|
37
|
+
actual = input.tanh(MPC::MPC_RNDNN, 50, 50)
|
38
|
+
actual.real.should eq GMP::F.new(expected_real, 50, 16)
|
39
|
+
actual.imag.should eq GMP::F.new(expected_imag, 50, 16)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should calculate the hyperbolic sine of ieee-754 double precision numbers' do
|
44
|
+
data = [
|
45
|
+
[["0x10000000000001p-53", 53, 16], ["0x1FFFFFFFFFFFFFp-53", 53, 16], ["0x1E938CBCEB16DFp-55", 53, 16], ["0x1B1F56FDEEF00Fp-53", 53, 16], MPC::MPC_RNDNN]
|
46
|
+
]
|
47
|
+
data.each do |expected_real, expected_imag, input_real, input_imag, rounding_mode|
|
48
|
+
actual = MPC.new([GMP::F.new(*input_real), GMP::F.new(*input_imag)]).tanh(rounding_mode)
|
49
|
+
actual.real.should eq GMP::F.new(*expected_real)
|
50
|
+
actual.imag.should eq GMP::F.new(*expected_imag)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/to_s_spec.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe MPC, '#to_s with base argument only' do
|
4
|
+
before do
|
5
|
+
@a = MPC.new(13)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should convert to_s correctly in default base' do
|
9
|
+
@a.to_s.should eq '(1.3000000000000000e+1 +0)'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should convert to_s correctly in base 2' do
|
13
|
+
@a.to_s(2).should eq '(1.1010000000000000000000000000000000000000000000000000p+3 +0)'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should convert to_s correctly in base 3' do
|
17
|
+
@a.to_s(3).should eq '(1.1100000000000000000000000000000000@+2 +0)'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should convert to_s correctly in base 4' do
|
21
|
+
@a.to_s(4).should eq '(3.10000000000000000000000000@+1 +0)'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should convert to_s correctly in base 8' do
|
25
|
+
@a.to_s(8).should eq '(1.500000000000000000@+1 +0)'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should convert to_s correctly in base 8' do
|
29
|
+
@a.to_s(8).should eq '(1.500000000000000000@+1 +0)'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should convert to_s correctly in base 10' do
|
33
|
+
@a.to_s(10).should eq '(1.3000000000000000e+1 +0)'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should convert to_s correctly in base 16' do
|
37
|
+
@a.to_s(16).should eq '(d.0000000000000 +0)'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should convert to_s correctly in base 32' do
|
41
|
+
@a.to_s(32).should eq '(d.00000000000 +0)'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe MPC, '#to_s with base argument only' do
|
46
|
+
before do
|
47
|
+
@a = MPC.new(13)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should convert to_s correctly with 0 sig figs' do
|
51
|
+
@a.to_s(10, 0).should eq '(1.3000000000000000e+1 +0)'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should convert to_s correctly with 1 sig figs' do
|
55
|
+
@a.to_s(10, 1).should eq '(1.e+1 +0)'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should convert to_s correctly with 2 sig figs' do
|
59
|
+
@a.to_s(10, 2).should eq '(1.3e+1 +0)'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should convert to_s correctly with 4 sig figs' do
|
63
|
+
@a.to_s(10, 4).should eq '(1.300e+1 +0)'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should convert to_s correctly with 8 sig figs' do
|
67
|
+
@a.to_s(10, 8).should eq '(1.3000000e+1 +0)'
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should convert to_s correctly with 16 sig figs' do
|
71
|
+
@a.to_s(10, 16).should eq '(1.300000000000000e+1 +0)'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should convert to_s correctly with 32 sig figs' do
|
75
|
+
@a.to_s(10, 32).should eq '(1.3000000000000000000000000000000e+1 +0)'
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gnu_mpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- srawlins
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: gnu_mpc - providing Ruby bindings to the MPC library.
|
15
|
+
email:
|
16
|
+
- sam.rawlins@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions:
|
19
|
+
- ext/extconf.rb
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ext/mpc.c
|
23
|
+
- ext/mpcrnd.c
|
24
|
+
- ext/ruby_gmp.h
|
25
|
+
- ext/ruby_mpc.h
|
26
|
+
- ext/extconf.rb
|
27
|
+
- lib/mpc.rb
|
28
|
+
- spec/acos_spec.rb
|
29
|
+
- spec/add_args_spec.rb
|
30
|
+
- spec/add_fr_spec.rb
|
31
|
+
- spec/add_spec.rb
|
32
|
+
- spec/asin_spec.rb
|
33
|
+
- spec/atan_spec.rb
|
34
|
+
- spec/conj_spec.rb
|
35
|
+
- spec/cos_spec.rb
|
36
|
+
- spec/cosh_spec.rb
|
37
|
+
- spec/exp_spec.rb
|
38
|
+
- spec/hash_arguments_spec.rb
|
39
|
+
- spec/log_spec.rb
|
40
|
+
- spec/mpc_single_function_args_spec.rb
|
41
|
+
- spec/neg_spec.rb
|
42
|
+
- spec/new_spec.rb
|
43
|
+
- spec/proj_spec.rb
|
44
|
+
- spec/real_spec.rb
|
45
|
+
- spec/rounding_spec.rb
|
46
|
+
- spec/sin_spec.rb
|
47
|
+
- spec/sinh_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
- spec/sqr_spec.rb
|
50
|
+
- spec/sqrt_spec.rb
|
51
|
+
- spec/sub_spec.rb
|
52
|
+
- spec/tan_spec.rb
|
53
|
+
- spec/tanh_spec.rb
|
54
|
+
- spec/to_s_spec.rb
|
55
|
+
- spec/version_spec.rb
|
56
|
+
- README.md
|
57
|
+
- manual.md
|
58
|
+
- manual.pdf
|
59
|
+
- COPYING.md
|
60
|
+
- Makefile
|
61
|
+
- Rakefile
|
62
|
+
- Gemfile
|
63
|
+
- Guardfile
|
64
|
+
- manual_template.latex
|
65
|
+
homepage: http://github.com/srawlins/gnu_mpc
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.8.7
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements:
|
84
|
+
- MPC compiled and working properly.
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.24
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Provides Ruby bindings to the MPC library.
|
90
|
+
test_files: []
|
91
|
+
has_rdoc: yard
|