gnu_mpc 0.8.2 → 0.9.0

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.
@@ -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/atan.dat
4
4
  describe MPC, '#atan' do
5
- it 'should calculate the inverse tangent of a pure real argument' do
5
+ it 'calculates the inverse tangent of a pure real argument' do
6
6
  data = [
7
7
  [["-0x16DCC57BB565FDp-52", 53, 16], [0], MPC.new([GMP::F(-7 ), -GMP::F(0)])],
8
8
  [["-0x1F730BD281F69Bp-53", 53, 16], [0], MPC.new([GMP::F(-1.5 ), -GMP::F(0)])],
@@ -17,12 +17,12 @@ describe MPC, '#atan' do
17
17
  ]
18
18
  data.each do |expected_real, expected_imag, input|
19
19
  actual = input.atan
20
- actual.real.should eq GMP::F.new(*expected_real)
21
- actual.imag.should eq GMP::F.new(*expected_imag)
20
+ expect(actual.real).to eq GMP::F.new(*expected_real)
21
+ expect(actual.imag).to eq GMP::F.new(*expected_imag)
22
22
  end
23
23
  end
24
24
 
25
- it 'should calculate the inverse tangent of a pure imaginary argument' do
25
+ it 'calculates the inverse tangent of a pure imaginary argument' do
26
26
  data = [
27
27
  [["-0x1921FB54442D18p-52", 53, 16], ["-0x1269621134DB92p-55", 53, 16], MPC.new([-GMP::F(0), GMP::F(-7 )])],
28
28
  [[ "0x1921FB54442D18p-52", 53, 16], ["-0x1269621134DB92p-55", 53, 16], MPC.new([ GMP::F(0), GMP::F(-7 )])],
@@ -40,32 +40,32 @@ describe MPC, '#atan' do
40
40
  ]
41
41
  data.each do |expected_real, expected_imag, input|
42
42
  actual = input.atan
43
- actual.real.should eq GMP::F.new(*expected_real)
44
- actual.imag.should eq GMP::F.new(*expected_imag)
43
+ expect(actual.real).to eq GMP::F.new(*expected_real)
44
+ expect(actual.imag).to eq GMP::F.new(*expected_imag)
45
45
  end
46
46
  end
47
47
 
48
- it 'should calculate the inverse tangent of a pure imaginary argument, 512 precision' do
48
+ it 'calculates the inverse tangent of a pure imaginary argument, 512 precision' do
49
49
  input = MPC.new([
50
50
  GMP::F(0, 512),
51
51
  GMP::F("0x1018734E311AB77B710F9212969B3C86E8F388BB7DA5BAF74ADE078F43D96456D088C8A0B2A370159DFB8D4A4BC51BCDA91F2DCD01B2EC610C62AA33FAD1688p-504", 512, 16)
52
52
  ], 512)
53
53
  actual = input.atan(MPC::MPC_RNDNZ, 512, 512)
54
- actual.real.should eq GMP::F.new("0x6487ED5110B4611A62633145C06E0E68948127044533E63A0105DF531D89CD9128A5043CC71A026EF7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E123p-510", 512, 16)
55
- actual.imag.should eq GMP::F.new("0x5D137113B914461DA3202D77346EE4980DA5FD0BAD68F5A7928DCA9F632750D9BFFA00654C523929F15DED554EC6BC476DB2C46FA433E569227085E0BDEA86FFp-509", 512, 16)
54
+ expect(actual.real).to eq GMP::F.new("0x6487ED5110B4611A62633145C06E0E68948127044533E63A0105DF531D89CD9128A5043CC71A026EF7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E123p-510", 512, 16)
55
+ expect(actual.imag).to eq GMP::F.new("0x5D137113B914461DA3202D77346EE4980DA5FD0BAD68F5A7928DCA9F632750D9BFFA00654C523929F15DED554EC6BC476DB2C46FA433E569227085E0BDEA86FFp-509", 512, 16)
56
56
  end
57
57
 
58
- it 'should calculate the inverse tangent of a pure imaginary argument, 12 precision' do
58
+ it 'calculates the inverse tangent of a pure imaginary argument, 12 precision' do
59
59
  input = MPC.new([
60
60
  GMP::F(0, 12),
61
61
  GMP::F("0x9380000000", 12, 16)
62
62
  ], 12)
63
63
  actual = input.atan
64
- actual.real.should eq GMP::F.new("0xC91p-11", 12, 16)
65
- actual.imag.should eq GMP::F.new("0x6F1p-50", 12, 16)
64
+ expect(actual.real).to eq GMP::F.new("0xC91p-11", 12, 16)
65
+ expect(actual.imag).to eq GMP::F.new("0x6F1p-50", 12, 16)
66
66
  end
67
67
 
68
- it 'should calculate the inverse tangent of a general inputs' do
68
+ it 'calculates the inverse tangent of a general inputs' do
69
69
  data = [
70
70
  [["0x91EA521228BFC46ACAp-118", 72, 16], ["-0x9E96A01DBAD6470974p-73", 72, 16], ["0x84C3E02A5C6DEE8410p-118", 72, 16], ["-0x99B43C52A95A21C220p-73", 72, 16], MPC::MPC_RNDUN],
71
71
  [["0x91EA521228BFC46AC9p-118", 72, 16], ["-0x9E96A01DBAD6470974p-73", 72, 16], ["0x84C3E02A5C6DEE8410p-118", 72, 16], ["-0x99B43C52A95A21C220p-73", 72, 16], MPC::MPC_RNDDD],
@@ -76,34 +76,34 @@ describe MPC, '#atan' do
76
76
  ]
77
77
  data.each do |expected_real, expected_imag, input_real, input_imag, rounding_mode|
78
78
  actual = MPC.new([GMP::F(*input_real), GMP::F(*input_imag)], 72).atan(rounding_mode)
79
- actual.real.should eq GMP::F.new(*expected_real)
80
- actual.imag.should eq GMP::F.new(*expected_imag)
79
+ expect(actual.real).to eq GMP::F.new(*expected_real)
80
+ expect(actual.imag).to eq GMP::F.new(*expected_imag)
81
81
  end
82
82
  end
83
83
 
84
- it 'should calculate the inverse tangent of a general inputs, 156 precision' do
84
+ it 'calculates the inverse tangent of a general inputs, 156 precision' do
85
85
  input = MPC.new([
86
86
  GMP::F("-0xF0CE58073F866A53F25DB85DE8D503FBDD81051p-109", 156, 16),
87
87
  GMP::F( "0xCF81D7C76BB9754A52056CB0F144B0C6700CC8Cp-128", 156, 16)
88
88
  ], 156)
89
89
  actual = input.atan
90
- actual.real.should eq GMP::F.new("-0xC90FDAA22167B20DB08A0C3B1FF415CABE49624p-155", 156, 16)
91
- actual.imag.should eq GMP::F.new("0xEA84E971BD52E49CCEE036E303D5ECB2D9D9B9Ap-222", 156, 16)
90
+ expect(actual.real).to eq GMP::F.new("-0xC90FDAA22167B20DB08A0C3B1FF415CABE49624p-155", 156, 16)
91
+ expect(actual.imag).to eq GMP::F.new("0xEA84E971BD52E49CCEE036E303D5ECB2D9D9B9Ap-222", 156, 16)
92
92
  end
93
93
 
94
- it 'should calculate the inverse tangent of a general inputs, 2 precision' do
94
+ it 'calculates the inverse tangent of a general inputs, 2 precision' do
95
95
  actual = MPC.new([GMP::F("0x1p-7", 2, 16), GMP::F(-1, 2, 16)], 2).atan
96
- actual.real.should eq GMP::F.new( 0.75, 2, 16)
97
- actual.imag.should eq GMP::F.new(-3, 2, 16)
96
+ expect(actual.real).to eq GMP::F.new( 0.75, 2, 16)
97
+ expect(actual.imag).to eq GMP::F.new(-3, 2, 16)
98
98
 
99
99
  actual = MPC.new([GMP::F("0x1p-7", 2, 16), GMP::F(1, 2, 16)], 2).atan
100
- actual.real.should eq GMP::F.new( 0.75, 2, 16)
101
- actual.imag.should eq GMP::F.new( 3, 2, 16)
100
+ expect(actual.real).to eq GMP::F.new( 0.75, 2, 16)
101
+ expect(actual.imag).to eq GMP::F.new( 3, 2, 16)
102
102
  end
103
103
 
104
- it 'should calculate the inverse tangent: "improve test coverage"' do
104
+ it 'calculates the inverse tangent: "improve test coverage"' do
105
105
  actual = MPC.new([GMP::F("-0xa.529626a89a1960@23", 57, 16), GMP::F("-0x3.9a5472b5709e74@14", 57, 16)], 57).atan
106
- actual.real.should eq GMP::F.new("-0x1.921fb54442d184", 57, 16)
107
- actual.imag.should eq GMP::F.new("-0x8.a7e33db93ecf18@-34", 57, 16)
106
+ expect(actual.real).to eq GMP::F.new("-0x1.921fb54442d184", 57, 16)
107
+ expect(actual.imag).to eq GMP::F.new("-0x8.a7e33db93ecf18@-34", 57, 16)
108
108
  end
109
109
  end
@@ -0,0 +1,20 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe MPC, "#fma" do
4
+ before do
5
+ @a = MPC.new([2, 0])
6
+ @b = MPC.new([1, 2])
7
+ @c = MPC.new([2, 2])
8
+ end
9
+
10
+ it "returns the product of an MPC and the first argument, and summed with the second argument" do
11
+ expect(@a.fma(@b, @c)).to eq(MPC.new([4, 6]))
12
+ end
13
+
14
+ it "accepts hash options" do
15
+ result = @a.fma(@b, @c, prec: 32)
16
+ expect(result).to eq(MPC.new([4, 6]))
17
+ expect(result.real.prec).to eq 32
18
+ expect(result.imag.prec).to eq 32
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe MPC, "#imag" do
4
+ it "returns the imaginary part of an MPC generated with a Fixnum" do
5
+ expect(MPC.new(0).imag).to eq GMP::F(0)
6
+ expect(MPC.new(1).imag).to eq GMP::F(0)
7
+ expect(MPC.new([0, 1]).imag).to eq GMP::F(1)
8
+ end
9
+
10
+ it "returns the imaginary part of an MPC generated with a GMP::Z" do
11
+ expect(MPC.new(GMP::Z(0)).imag).to eq GMP::F(0)
12
+ expect(MPC.new(GMP::Z(1)).imag).to eq GMP::F(0)
13
+ expect(MPC.new([GMP::Z(7), GMP::Z(2**64)]).imag).to eq GMP::F(2**64)
14
+ expect(MPC.new([GMP::Z(0), GMP::Z(1)]).imag).to eq GMP::F(1)
15
+ end
16
+
17
+ it "returns the imaginary part an MPC generated with a Float" do
18
+ expect(MPC.new(0.0).imag).to eq GMP::F(0)
19
+ expect(MPC.new([0.0, 1.0]).imag).to eq GMP::F(1)
20
+ expect(MPC.new([1.0, 1.0]).imag).to eq GMP::F(1)
21
+ expect(MPC.new([2*Math::PI, Math::PI]).imag).to eq GMP::F(Math::PI)
22
+ end
23
+ end
@@ -1,26 +1,34 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  # All tests adapted from MPC 1.0.1's tests/log10.dat
4
- describe MPC, '#log' do
5
- it 'should calculate the base 10 logarithm of +1 +- i*0' do
4
+ describe MPC, '#log10' do
5
+ it 'calculates the base 10 logarithm of +1 +- i*0' do
6
+ pending("log10 introduced in MPC 1.0.0") if MPC::MPC_VERSION[0] == "0"
7
+
6
8
  actual = MPC.new([1, 0], 2).log10
7
- actual.real.should eq 0
8
- actual.imag.should eq 0
9
+ expect(actual.real).to eq 0
10
+ expect(actual.imag).to eq 0
9
11
  end
10
12
 
11
- it 'should calculate the base 10 logarithm of 10 +- i*0' do
13
+ it 'calculates the base 10 logarithm of 10 +- i*0' do
14
+ pending("log10 introduced in MPC 1.0.0") if MPC::MPC_VERSION[0] == "0"
15
+
12
16
  actual = MPC.new([GMP::F(10, 4), GMP::F(0, 2)]).log10
13
- actual.real.should eq 1
14
- actual.imag.should eq 0
17
+ expect(actual.real).to eq 1
18
+ expect(actual.imag).to eq 0
15
19
  end
16
20
 
17
- it 'should calculate the base 10 logarithm of 100 +- i*0' do
21
+ it 'calculates the base 10 logarithm of 100 +- i*0' do
22
+ pending("log10 introduced in MPC 1.0.0") if MPC::MPC_VERSION[0] == "0"
23
+
18
24
  actual = MPC.new([GMP::F(100, 5), GMP::F(0, 2)]).log10
19
- actual.real.should eq 2
20
- actual.imag.should eq 0
25
+ expect(actual.real).to eq 2
26
+ expect(actual.imag).to eq 0
21
27
  end
22
28
 
23
- it 'should calculate the base 10 logarithm of x +i*y with either x or y zero and the other non-zero' do
29
+ it 'calculates the base 10 logarithm of x +i*y with either x or y zero and the other non-zero' do
30
+ pending("log10 introduced in MPC 1.0.0") if MPC::MPC_VERSION[0] == "0"
31
+
24
32
  data = [
25
33
  [["0x13afeb354b7d97p-52", 53, 16], [ 0, 2], MPC.new([GMP::F( "0x11", 5, 16), GMP::F(0, 2)]), MPC::MPC_RNDNN],
26
34
  [["0x13afeb354b7d97p-52", 53, 16], [ "0x15d47c4cb2fba1p-53", 53, 16], MPC.new([GMP::F(0, 2), GMP::F( "0x11", 5, 16)]), MPC::MPC_RNDNN],
@@ -30,8 +38,8 @@ describe MPC, '#log' do
30
38
  ]
31
39
  data.each do |expected_real, expected_imag, input, rounding_mode|
32
40
  actual = input.log10(rounding_mode)
33
- actual.real.should eq GMP::F.new(*expected_real)
34
- actual.imag.should eq GMP::F.new(*expected_imag)
41
+ expect(actual.real).to eq GMP::F.new(*expected_real)
42
+ expect(actual.imag).to eq GMP::F.new(*expected_imag)
35
43
  end
36
44
  end
37
45
 
@@ -7,35 +7,35 @@ describe "MPC_SINGLE_FUNCTION args" do
7
7
  :sinh, :cosh, :tanh,
8
8
  :asin, :acos, :atan
9
9
  ]
10
- @z = MPC.new(0,0)
10
+ @z = MPC.new(0)
11
11
  end
12
12
  it "should accept no arguments" do
13
13
  @functions.each do |func|
14
- expect { @z.send(func) }.to_not raise_error(ArgumentError)
14
+ expect { @z.send(func) }.to_not raise_error
15
15
  end
16
16
  end
17
17
 
18
18
  it "should accept a single rounding mode argument, MPC_RNDNN" do
19
19
  @functions.each do |func|
20
- expect { @z.send(func, MPC::MPC_RNDNN) }.to_not raise_error(ArgumentError)
20
+ expect { @z.send(func, MPC::MPC_RNDNN) }.to_not raise_error
21
21
  end
22
22
  end
23
23
 
24
24
  it "should accept a single rounding mode argument, MPC_RNDZD" do
25
25
  @functions.each do |func|
26
- expect { @z.send(func, MPC::MPC_RNDZD) }.to_not raise_error(ArgumentError)
26
+ expect { @z.send(func, MPC::MPC_RNDZD) }.to_not raise_error
27
27
  end
28
28
  end
29
29
 
30
30
  it "should accept a single rounding mode argument and a single precision" do
31
31
  @functions.each do |func|
32
- expect { @z.send(func, MPC::MPC_RNDZZ, 128) }.to_not raise_error(ArgumentError)
32
+ expect { @z.send(func, MPC::MPC_RNDZZ, 128) }.to_not raise_error
33
33
  end
34
34
  end
35
35
 
36
36
  it "should accept a single rounding mode argument and two precisions" do
37
37
  @functions.each do |func|
38
- expect { @z.send(func, MPC::MPC_RNDZZ, 128, 256) }.to_not raise_error(ArgumentError)
38
+ expect { @z.send(func, MPC::MPC_RNDZZ, 128, 256) }.to_not raise_error
39
39
  end
40
40
  end
41
41
  end
@@ -8,81 +8,95 @@ describe MPC, '#initialize without precision or rounding args' do
8
8
  @q2 = GMP::Q(-2,3)
9
9
  @f1 = GMP::F(1.5)
10
10
  @f2 = GMP::F(-2.5)
11
+ @big_2_64 = 2**64
12
+ @big_2_65 = 2**65
13
+ @z_2_64 = GMP::Z(2**64)
14
+ @z_2_65 = GMP::Z(2**65)
11
15
  end
12
- it 'should not raise anything when initialized with no args' do
16
+ it 'does not raise anything when initialized with no args' do
13
17
  expect { MPC.new() }.to_not raise_error
14
18
  end
15
19
 
16
- it 'should not raise anything when initialized with 0' do
20
+ it 'does not raise anything when initialized with 0' do
17
21
  expect { MPC.new(0) }.to_not raise_error
18
22
  end
19
23
 
20
- it 'should not raise anything when initialized with a negative Fixnum' do
24
+ it 'does not raise anything when initialized with a negative Fixnum' do
21
25
  expect { MPC.new(-32) }.to_not raise_error
22
26
  end
23
27
 
24
- it 'should not raise anything when initialized with a positive Fixnum' do
28
+ it 'does not raise anything when initialized with a positive Fixnum' do
25
29
  expect { MPC.new(32) }.to_not raise_error
26
30
  end
27
31
 
28
- it 'should not raise anything when initialized with 0.0' do
32
+ it "can be instantiated from a Bignum" do
33
+ expect { MPC.new(@big_2_64) }.to_not raise_error
34
+ expect(MPC.new(@big_2_64)).to eq(MPC.new(@z_2_64))
35
+ end
36
+
37
+ it 'does not raise anything when initialized with 0.0' do
29
38
  expect { MPC.new(0.0) }.to_not raise_error
30
39
  end
31
40
 
32
- it 'should not raise anything when initialized with a positive Float' do
41
+ it 'does not raise anything when initialized with a positive Float' do
33
42
  expect { MPC.new(3.14) }.to_not raise_error
34
43
  expect { MPC.new(1.618) }.to_not raise_error
35
44
  end
36
45
 
37
- it 'should not raise anything when initialized with a positive GMP::Z' do
46
+ it 'does not raise anything when initialized with a positive GMP::Z' do
38
47
  expect { MPC.new(@z1) }.to_not raise_error
39
48
  end
40
49
 
41
- it 'should not raise anything when initialized with a negative GMP::Z' do
50
+ it 'does not raise anything when initialized with a negative GMP::Z' do
42
51
  expect { MPC.new(@z2) }.to_not raise_error
43
52
  end
44
53
 
45
- it 'should not raise anything when initialized with a positive GMP::Q' do
54
+ it 'does not raise anything when initialized with a positive GMP::Q' do
46
55
  expect { MPC.new(@q1) }.to_not raise_error
47
56
  end
48
57
 
49
- it 'should not raise anything when initialized with a negative GMP::Q' do
58
+ it 'does not raise anything when initialized with a negative GMP::Q' do
50
59
  expect { MPC.new(@q2) }.to_not raise_error
51
60
  end
52
61
 
53
- it 'should not raise anything when initialized with a positive GMP::F' do
62
+ it 'does not raise anything when initialized with a positive GMP::F' do
54
63
  expect { MPC.new(@f1) }.to_not raise_error
55
64
  end
56
65
 
57
- it 'should not raise anything when initialized with a negative GMP::F' do
66
+ it 'does not raise anything when initialized with a negative GMP::F' do
58
67
  expect { MPC.new(@f2) }.to_not raise_error
59
68
  end
60
69
 
61
- it 'should not raise anything when initialized with an Array of 0\'s' do
62
- expect { MPC.new([0,0]) }.to_not raise_error
70
+ it 'does not raise anything when initialized with an Array of 0\'s' do
71
+ expect { MPC.new([0, 0]) }.to_not raise_error
63
72
  end
64
73
 
65
- it 'should not raise anything when initialized with an Array of Fixnum\'s' do
74
+ it 'does not raise anything when initialized with an Array of Fixnum\'s' do
66
75
  expect { MPC.new([-2**10, 2**11]) }.to_not raise_error
67
76
  end
68
77
 
69
- it 'should not raise anything when initialized with an Array of Float\'s' do
78
+ it "can be instantiated from two Bignums" do
79
+ expect { MPC.new([@big_2_64, @big_2_65]) }.to_not raise_error
80
+ expect(MPC.new([@big_2_64, @big_2_65])).to eq(MPC.new([@z_2_64, @z_2_65]))
81
+ end
82
+
83
+ it 'does not raise anything when initialized with an Array of Float\'s' do
70
84
  expect { MPC.new([1.4142135623730951, 1.4142135623730951]) }.to_not raise_error
71
85
  end
72
86
 
73
- it 'should not raise anything when initialized with an Array of GMP::Z\'s' do
87
+ it 'does not raise anything when initialized with an Array of GMP::Z\'s' do
74
88
  expect { MPC.new([@z1, @z2]) }.to_not raise_error
75
89
  end
76
90
 
77
- it 'should not raise anything when initialized with an Array of GMP::Q\'s' do
91
+ it 'does not raise anything when initialized with an Array of GMP::Q\'s' do
78
92
  expect { MPC.new([@q1, @q2]) }.to_not raise_error
79
93
  end
80
94
 
81
- it 'should not raise anything when initialized with an Array of GMP::F\'s' do
95
+ it 'does not raise anything when initialized with an Array of GMP::F\'s' do
82
96
  expect { MPC.new([@f1, @f2]) }.to_not raise_error
83
97
  end
84
98
 
85
- it 'should raise TypeError when initialized with an Array of mixed types' do
99
+ it 'raises TypeError when initialized with an Array of mixed types' do
86
100
  expect { MPC.new([0, 0.0]) }.to raise_error(TypeError)
87
101
  expect { MPC.new([0, @z1]) }.to raise_error(TypeError)
88
102
  expect { MPC.new([@f1, 0.0]) }.to raise_error(TypeError)
@@ -90,8 +104,25 @@ describe MPC, '#initialize without precision or rounding args' do
90
104
  expect { MPC.new([@q1, 42]) }.to raise_error(TypeError)
91
105
  end
92
106
 
93
- it 'should initialize default values correctly' do
94
- MPC.new(0).should eq MPC.new()
95
- MPC.new(0.0).should eq MPC.new()
107
+ it 'initializes default values correctly' do
108
+ expect(MPC.new(0)).to eq MPC.new()
109
+ expect(MPC.new(0.0)).to eq MPC.new()
110
+ end
111
+
112
+ it 'raises when the precision is out-of-bounds' do
113
+ expect { MPC.new(0, -1) }.to raise_error(RangeError)
114
+ expect { MPC.new(0, 0) }.to raise_error(RangeError)
115
+ expect { MPC.new(0, 1) }.to raise_error(RangeError)
116
+ end
117
+ end
118
+
119
+ describe MPC, '#initialize with precision arguments' do
120
+ it "accepts a shared precision" do
121
+ expect(MPC.new(7, 32).prec).to eq(32)
122
+ end
123
+
124
+ it "accepts individual precisions" do
125
+ expect(MPC.new(7, 32, 64).prec).to eq(0)
126
+ expect(MPC.new(7, 32, 64).prec2).to eq([32, 64])
96
127
  end
97
128
  end
@@ -0,0 +1,79 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe MPC, '#pow' do
4
+ before do
5
+ @w = MPC.new([0, 1])
6
+ end
7
+
8
+ it 'calculates the value of a complex number raised to a Fixnum power' do
9
+ w = @w.pow 2
10
+
11
+ expect(w.real).to eq -1
12
+ expect(w.imag).to eq 0
13
+
14
+ w = @w.pow 3
15
+
16
+ expect(w.real).to eq 0
17
+ expect(w.imag).to eq -1
18
+ end
19
+
20
+ it 'calculates the value of a complex number raised to a GMP::Z power' do
21
+ w = @w.pow GMP::Z(4)
22
+
23
+ expect(w.real).to eq 1
24
+ expect(w.imag).to eq 0
25
+ end
26
+
27
+ it 'calculates the value of a complaex number raised to a Float power' do
28
+ w = @w.pow 0.5
29
+
30
+ expect(w.real).to eq GMP::F(0.5).sqrt
31
+ expect(w.imag).to eq GMP::F(0.5).sqrt
32
+ end
33
+
34
+ it 'calculates the value of a complaex number raised to a GMP::F power' do
35
+ w = @w.pow GMP::F(0.5)
36
+
37
+ expect(w.real).to eq GMP::F(0.5).sqrt
38
+ expect(w.imag).to eq GMP::F(0.5).sqrt
39
+ end
40
+ end
41
+
42
+ describe MPC, '#**' do
43
+ before do
44
+ @w = MPC.new([0, 1])
45
+ end
46
+
47
+ it 'calculates the value of a complex number raised to a Fixnum power' do
48
+ w = @w ** 2
49
+
50
+ expect(w.real).to eq -1
51
+ expect(w.imag).to eq 0
52
+
53
+ w = @w ** 3
54
+
55
+ expect(w.real).to eq 0
56
+ expect(w.imag).to eq -1
57
+ end
58
+
59
+ it 'calculates the value of a complex number raised to a GMP::Z power' do
60
+ w = @w ** GMP::Z(4)
61
+
62
+ expect(w.real).to eq 1
63
+ expect(w.imag).to eq 0
64
+ end
65
+
66
+ it 'calculates the value of a complaex number raised to a Float power' do
67
+ w = @w ** 0.5
68
+
69
+ expect(w.real).to eq GMP::F(0.5).sqrt
70
+ expect(w.imag).to eq GMP::F(0.5).sqrt
71
+ end
72
+
73
+ it 'calculates the value of a complaex number raised to a GMP::F power' do
74
+ w = @w ** GMP::F(0.5)
75
+
76
+ expect(w.real).to eq GMP::F(0.5).sqrt
77
+ expect(w.imag).to eq GMP::F(0.5).sqrt
78
+ end
79
+ end