rubysl-complex 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +2 -0
  8. data/lib/complex.rb +1 -0
  9. data/lib/rubysl/complex.rb +2 -0
  10. data/lib/rubysl/complex/complex.rb +659 -0
  11. data/lib/rubysl/complex/version.rb +5 -0
  12. data/rubysl-complex.gemspec +23 -0
  13. data/spec/Complex_spec.rb +9 -0
  14. data/spec/abs2_spec.rb +10 -0
  15. data/spec/abs_spec.rb +10 -0
  16. data/spec/angle_spec.rb +7 -0
  17. data/spec/arg_spec.rb +7 -0
  18. data/spec/coerce_spec.rb +11 -0
  19. data/spec/comparison_spec.rb +23 -0
  20. data/spec/conj_spec.rb +7 -0
  21. data/spec/conjugate_spec.rb +7 -0
  22. data/spec/constants_spec.rb +9 -0
  23. data/spec/denominator_spec.rb +20 -0
  24. data/spec/divide_spec.rb +9 -0
  25. data/spec/equal_value_spec.rb +9 -0
  26. data/spec/exponent_spec.rb +10 -0
  27. data/spec/float/angle_spec.rb +9 -0
  28. data/spec/float/arg_spec.rb +9 -0
  29. data/spec/generic_spec.rb +25 -0
  30. data/spec/hash_spec.rb +10 -0
  31. data/spec/imag_spec.rb +10 -0
  32. data/spec/image_spec.rb +7 -0
  33. data/spec/inspect_spec.rb +10 -0
  34. data/spec/math/acos_spec.rb +30 -0
  35. data/spec/math/acosh_spec.rb +30 -0
  36. data/spec/math/asin_spec.rb +30 -0
  37. data/spec/math/asinh_spec.rb +30 -0
  38. data/spec/math/atan2_spec.rb +30 -0
  39. data/spec/math/atan_spec.rb +30 -0
  40. data/spec/math/atanh_spec.rb +34 -0
  41. data/spec/math/cos_spec.rb +30 -0
  42. data/spec/math/cosh_spec.rb +30 -0
  43. data/spec/math/exp_spec.rb +30 -0
  44. data/spec/math/fixtures/classes.rb +3 -0
  45. data/spec/math/log10_spec.rb +30 -0
  46. data/spec/math/log_spec.rb +30 -0
  47. data/spec/math/shared/acos.rb +41 -0
  48. data/spec/math/shared/acosh.rb +37 -0
  49. data/spec/math/shared/asin.rb +47 -0
  50. data/spec/math/shared/asinh.rb +32 -0
  51. data/spec/math/shared/atan.rb +32 -0
  52. data/spec/math/shared/atan2.rb +34 -0
  53. data/spec/math/shared/atanh.rb +30 -0
  54. data/spec/math/shared/cos.rb +30 -0
  55. data/spec/math/shared/cosh.rb +28 -0
  56. data/spec/math/shared/exp.rb +28 -0
  57. data/spec/math/shared/log.rb +39 -0
  58. data/spec/math/shared/log10.rb +41 -0
  59. data/spec/math/shared/sin.rb +30 -0
  60. data/spec/math/shared/sinh.rb +28 -0
  61. data/spec/math/shared/sqrt.rb +34 -0
  62. data/spec/math/shared/tan.rb +28 -0
  63. data/spec/math/shared/tanh.rb +32 -0
  64. data/spec/math/sin_spec.rb +30 -0
  65. data/spec/math/sinh_spec.rb +30 -0
  66. data/spec/math/sqrt_spec.rb +30 -0
  67. data/spec/math/tan_spec.rb +30 -0
  68. data/spec/math/tanh_spec.rb +30 -0
  69. data/spec/minus_spec.rb +9 -0
  70. data/spec/modulo_spec.rb +29 -0
  71. data/spec/multiply_spec.rb +9 -0
  72. data/spec/new_spec.rb +41 -0
  73. data/spec/numerator_spec.rb +12 -0
  74. data/spec/numeric/angle_spec.rb +11 -0
  75. data/spec/numeric/arg_spec.rb +11 -0
  76. data/spec/numeric/conj_spec.rb +11 -0
  77. data/spec/numeric/conjugate_spec.rb +11 -0
  78. data/spec/numeric/im_spec.rb +9 -0
  79. data/spec/numeric/imag_spec.rb +11 -0
  80. data/spec/numeric/image_spec.rb +11 -0
  81. data/spec/numeric/polar_spec.rb +11 -0
  82. data/spec/numeric/real_spec.rb +11 -0
  83. data/spec/plus_spec.rb +9 -0
  84. data/spec/polar_spec.rb +13 -0
  85. data/spec/real_spec.rb +10 -0
  86. data/spec/to_s_spec.rb +9 -0
  87. metadata +259 -0
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/atan', __FILE__)
3
+
4
+ describe "Math#atan" do
5
+ it_behaves_like :complex_math_atan, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:atan)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#atan!" do
14
+ it_behaves_like :complex_math_atan_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:atan!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.atan" do
23
+ it_behaves_like :complex_math_atan, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.atan!" do
28
+ it_behaves_like :complex_math_atan_bang, :_, Math
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ require 'complex'
2
+ require File.expand_path('../../../../fixtures/math/common', __FILE__)
3
+ require File.expand_path('../../../../shared/math/atanh', __FILE__)
4
+ require File.expand_path('../shared/atanh', __FILE__)
5
+
6
+ describe "Math#atanh" do
7
+ it_behaves_like :math_atanh_base, :atanh, IncludesMath.new
8
+ it_behaves_like :complex_math_atanh_complex, :atanh, IncludesMath.new
9
+
10
+ it_behaves_like :math_atanh_private, :atanh, IncludesMath.new
11
+ end
12
+
13
+ ruby_version_is ""..."1.9" do
14
+ describe "Math#atanh!" do
15
+ it_behaves_like :math_atanh_base, :atanh!, IncludesMath.new
16
+ it_behaves_like :math_atanh_no_complex, :atanh!, IncludesMath.new
17
+ it_behaves_like :complex_math_atanh_no_complex, :atanh!, IncludesMath.new
18
+
19
+ it_behaves_like :math_atanh_private, :atanh!, IncludesMath.new
20
+ end
21
+ end
22
+
23
+ describe "Math.atanh" do
24
+ it_behaves_like :math_atanh_base, :atanh, Math
25
+ it_behaves_like :complex_math_atanh_complex, :atanh, Math
26
+ end
27
+
28
+ ruby_version_is ""..."1.9" do
29
+ describe "Math.atanh!" do
30
+ it_behaves_like :math_atanh_base, :atanh!, Math
31
+ it_behaves_like :math_atanh_no_complex, :atanh!, Math
32
+ it_behaves_like :complex_math_atanh_no_complex, :atanh!, Math
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/cos', __FILE__)
3
+
4
+ describe "Math#cos" do
5
+ it_behaves_like :complex_math_cos, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:cos)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#cos!" do
14
+ it_behaves_like :complex_math_cos_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:cos!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.cos" do
23
+ it_behaves_like :complex_math_cos, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.cos!" do
28
+ it_behaves_like :complex_math_cos_bang, :_, Math
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/cosh', __FILE__)
3
+
4
+ describe "Math#cosh" do
5
+ it_behaves_like :complex_math_cosh, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:cosh)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#cosh!" do
14
+ it_behaves_like :complex_math_cosh_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:cosh!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.cosh" do
23
+ it_behaves_like :complex_math_cosh, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.cosh!" do
28
+ it_behaves_like :complex_math_cosh_bang, :_, Math
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/exp', __FILE__)
3
+
4
+ describe "Math#exp" do
5
+ it_behaves_like :complex_math_exp, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:exp)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#exp!" do
14
+ it_behaves_like :complex_math_exp_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:exp!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.exp" do
23
+ it_behaves_like :complex_math_exp, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.exp!" do
28
+ it_behaves_like :complex_math_exp_bang, :_, Math
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ class IncludesMath
2
+ include Math
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/log10', __FILE__)
3
+
4
+ describe "Math#log10" do
5
+ it_behaves_like :complex_math_log10, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:log10)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#log10!" do
14
+ it_behaves_like :complex_math_log10_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:log10!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.log10" do
23
+ it_behaves_like :complex_math_log10, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.log10!" do
28
+ it_behaves_like :complex_math_log10_bang, :_, Math
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/log', __FILE__)
3
+
4
+ describe "Math#log" do
5
+ it_behaves_like :complex_math_log, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:log)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#log!" do
14
+ it_behaves_like :complex_math_log_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:log!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.log" do
23
+ it_behaves_like :complex_math_log, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.log!" do
28
+ it_behaves_like :complex_math_log_bang, :_, Math
29
+ end
30
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../../fixtures/classes', __FILE__)
2
+
3
+ describe :complex_math_acos, :shared => true do
4
+ it "returns the arccosine of the passed argument" do
5
+ @object.send(:acos, 1).should be_close(0.0, TOLERANCE)
6
+ @object.send(:acos, 0).should be_close(1.5707963267949, TOLERANCE)
7
+ @object.send(:acos, -1).should be_close(Math::PI,TOLERANCE)
8
+ end
9
+
10
+ it "returns the arccosine for Complex numbers" do
11
+ @object.send(:acos, Complex(3, 4)).should be_close(Complex(0.93681246115572, -2.30550903124348), TOLERANCE)
12
+ end
13
+
14
+ it "returns the arccosine for numbers greater than 1.0 as a Complex number" do
15
+ @object.send(:acos, 1.0001).should be_close(Complex(0.0, 0.0141420177752494), TOLERANCE)
16
+ end
17
+
18
+ it "returns the arccosine for numbers less than -1.0 as a Complex number" do
19
+ @object.send(:acos, -1.0001).should be_close(Complex(3.14159265358979, -0.0141420177752495), TOLERANCE)
20
+ end
21
+ end
22
+
23
+ describe :complex_math_acos_bang, :shared => true do
24
+ it "returns the arccosine of the argument" do
25
+ @object.send(:acos!, 1).should be_close(0.0, TOLERANCE)
26
+ @object.send(:acos!, 0).should be_close(1.5707963267949, TOLERANCE)
27
+ @object.send(:acos!, -1).should be_close(Math::PI,TOLERANCE)
28
+ end
29
+
30
+ it "raises a TypeError when passed a Complex number" do
31
+ lambda { @object.send(:acos!, Complex(4, 5)) }.should raise_error(TypeError)
32
+ end
33
+
34
+ it "raises an Errno::EDOM for numbers greater than 1.0" do
35
+ lambda { @object.send(:acos!, 1.0001) }.should raise_error(Errno::EDOM)
36
+ end
37
+
38
+ it "raises an Errno::EDOM for numbers less than -1.0" do
39
+ lambda { @object.send(:acos!, -1.0001) }.should raise_error(Errno::EDOM)
40
+ end
41
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path('../../fixtures/classes', __FILE__)
2
+
3
+ describe :complex_math_acosh, :shared => true do
4
+ it "returns the principle value of the inverse hyperbolic cosine of the argument" do
5
+ @object.send(:acosh, 14.2).should be_close(3.345146999647, TOLERANCE)
6
+ @object.send(:acosh, 1.0).should be_close(0.0, TOLERANCE)
7
+ end
8
+
9
+ it "returns the principle value of the inverse hyperbolic cosine for numbers less than 1.0 as a Complex number" do
10
+ @object.send(:acosh, 1.0 - TOLERANCE).should be_close(Complex(0.0, 0.00774598605746135), TOLERANCE)
11
+ @object.send(:acosh, 0).should be_close(Complex(0.0, 1.5707963267949), TOLERANCE)
12
+ @object.send(:acosh, -1.0).should be_close(Complex(0.0, 3.14159265358979), TOLERANCE)
13
+ end
14
+
15
+ it "returns the principle value of the inverse hyperbolic cosine for Complex numbers" do
16
+ @object.send(:acosh, Complex(3, 4))
17
+ @object.send(:acosh, Complex(3, 4)).image.should be_close(0.93681246115572, TOLERANCE)
18
+ @object.send(:acosh, Complex(3, 4)).real.should be_close(2.305509031243477, TOLERANCE)
19
+ end
20
+ end
21
+
22
+ describe :complex_math_acosh_bang, :shared => true do
23
+ it "returns the principle value of the inverse hyperbolic cosine of the argument" do
24
+ @object.send(:acosh!, 14.2).should be_close(3.345146999647, TOLERANCE)
25
+ @object.send(:acosh!, 1.0).should be_close(0.0, TOLERANCE)
26
+ end
27
+
28
+ it "raises Errno::EDOM for numbers less than 1.0" do
29
+ lambda { @object.send(:acosh!, 1.0 - TOLERANCE) }.should raise_error(Errno::EDOM)
30
+ lambda { @object.send(:acosh!, 0) }.should raise_error(Errno::EDOM)
31
+ lambda { @object.send(:acosh!, -1.0) }.should raise_error(Errno::EDOM)
32
+ end
33
+
34
+ it "raises a TypeError when passed a Complex number" do
35
+ lambda { @object.send(:acosh!, Complex(4, 5)) }.should raise_error(TypeError)
36
+ end
37
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path('../../fixtures/classes', __FILE__)
2
+
3
+ describe :complex_math_asin, :shared => true do
4
+ it "returns the arcsine of the argument" do
5
+ @object.send(:asin, 1).should be_close(Math::PI/2, TOLERANCE)
6
+ @object.send(:asin, 0).should be_close(0.0, TOLERANCE)
7
+ @object.send(:asin, -1).should be_close(-Math::PI/2, TOLERANCE)
8
+ @object.send(:asin, 0.25).should be_close(0.252680255142079, TOLERANCE)
9
+ @object.send(:asin, 0.50).should be_close(0.523598775598299, TOLERANCE)
10
+ @object.send(:asin, 0.75).should be_close(0.8480620789814816,TOLERANCE)
11
+ end
12
+
13
+ it "returns the arcsine for Complex numbers" do
14
+ @object.send(:asin, Complex(3, 4)).should be_close(Complex(0.633983865639174, 2.30550903124347), TOLERANCE)
15
+ end
16
+
17
+ it "returns a Complex number when the argument is greater than 1.0" do
18
+ @object.send(:asin, 1.0001).should be_close(Complex(1.5707963267949, -0.0141420177752494), TOLERANCE)
19
+ end
20
+
21
+ it "returns a Complex number when the argument is less than -1.0" do
22
+ @object.send(:asin, -1.0001).should be_close(Complex(-1.5707963267949, 0.0141420177752494), TOLERANCE)
23
+ end
24
+ end
25
+
26
+ describe :complex_math_asin_bang, :shared => true do
27
+ it "returns the arcsine of the argument" do
28
+ @object.send(:asin!, 1).should be_close(Math::PI/2, TOLERANCE)
29
+ @object.send(:asin!, 0).should be_close(0.0, TOLERANCE)
30
+ @object.send(:asin!, -1).should be_close(-Math::PI/2, TOLERANCE)
31
+ @object.send(:asin!, 0.25).should be_close(0.252680255142079, TOLERANCE)
32
+ @object.send(:asin!, 0.50).should be_close(0.523598775598299, TOLERANCE)
33
+ @object.send(:asin!, 0.75).should be_close(0.8480620789814816,TOLERANCE)
34
+ end
35
+
36
+ it "raises an Errno::EDOM if the argument is greater than 1.0" do
37
+ lambda { @object.send(:asin!, 1.0001) }.should raise_error( Errno::EDOM)
38
+ end
39
+
40
+ it "raises an Errno::EDOM if the argument is less than -1.0" do
41
+ lambda { @object.send(:asin!, -1.0001) }.should raise_error( Errno::EDOM)
42
+ end
43
+
44
+ it "raises a TypeError when passed a Complex number" do
45
+ lambda { @object.send(:asin!, Complex(4, 5)) }.should raise_error(TypeError)
46
+ end
47
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../../fixtures/classes', __FILE__)
2
+
3
+ describe :complex_math_asinh, :shared => true do
4
+ it "returns the inverse hyperbolic sin of the argument" do
5
+ @object.send(:asinh, 1.5).should be_close(1.19476321728711, TOLERANCE)
6
+ @object.send(:asinh, -2.97).should be_close(-1.8089166921397, TOLERANCE)
7
+ @object.send(:asinh, 0.0).should == 0.0
8
+ @object.send(:asinh, -0.0).should == -0.0
9
+ @object.send(:asinh, 1.05367e-08).should be_close(1.05367e-08, TOLERANCE)
10
+ @object.send(:asinh, -1.05367e-08).should be_close(-1.05367e-08, TOLERANCE)
11
+ end
12
+
13
+ it "returns the inverse hyperbolic sin for Complex numbers" do
14
+ @object.send(:asinh, Complex(3, 4)).should be_close(Complex(2.29991404087927, 0.917616853351479), TOLERANCE)
15
+ @object.send(:asinh, Complex(3.5, -4)).should be_close(Complex(2.36263337274419, -0.843166327537659), TOLERANCE)
16
+ end
17
+ end
18
+
19
+ describe :complex_math_asinh_bang, :shared => true do
20
+ it "returns the inverse hyperbolic sin of the argument" do
21
+ @object.send(:asinh!, 1.5).should be_close(1.19476321728711, TOLERANCE)
22
+ @object.send(:asinh!, -2.97).should be_close(-1.8089166921397, TOLERANCE)
23
+ @object.send(:asinh!, 0.0).should == 0.0
24
+ @object.send(:asinh!, -0.0).should == -0.0
25
+ @object.send(:asinh!, 1.05367e-08).should be_close(1.05367e-08, TOLERANCE)
26
+ @object.send(:asinh!, -1.05367e-08).should be_close(-1.05367e-08, TOLERANCE)
27
+ end
28
+
29
+ it "raises a TypeError when passed a Complex number" do
30
+ lambda { @object.send(:asinh!, Complex(4, 5)) }.should raise_error(TypeError)
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../../fixtures/classes', __FILE__)
2
+
3
+ describe :complex_math_atan, :shared => true do
4
+ it "returns the arctangent of the argument" do
5
+ @object.send(:atan, 1).should be_close(Math::PI/4, TOLERANCE)
6
+ @object.send(:atan, 0).should be_close(0.0, TOLERANCE)
7
+ @object.send(:atan, -1).should be_close(-Math::PI/4, TOLERANCE)
8
+ @object.send(:atan, 0.25).should be_close(0.244978663126864, TOLERANCE)
9
+ @object.send(:atan, 0.50).should be_close(0.463647609000806, TOLERANCE)
10
+ @object.send(:atan, 0.75).should be_close(0.643501108793284, TOLERANCE)
11
+ end
12
+
13
+ it "returns the arctangent for Complex numbers" do
14
+ @object.send(:atan, Complex(3, 4)).should be_close(Complex(1.44830699523146, 0.158997191679999), TOLERANCE)
15
+ @object.send(:atan, Complex(3.5, -4)).should be_close(Complex(1.44507428165589, -0.140323762363786), TOLERANCE)
16
+ end
17
+ end
18
+
19
+ describe :complex_math_atan_bang, :shared => true do
20
+ it "returns the arctangent of the argument" do
21
+ @object.send(:atan!, 1).should be_close(Math::PI/4, TOLERANCE)
22
+ @object.send(:atan!, 0).should be_close(0.0, TOLERANCE)
23
+ @object.send(:atan!, -1).should be_close(-Math::PI/4, TOLERANCE)
24
+ @object.send(:atan!, 0.25).should be_close(0.244978663126864, TOLERANCE)
25
+ @object.send(:atan!, 0.50).should be_close(0.463647609000806, TOLERANCE)
26
+ @object.send(:atan!, 0.75).should be_close(0.643501108793284, TOLERANCE)
27
+ end
28
+
29
+ it "raises a TypeError when passed a Complex number" do
30
+ lambda { @object.send(:atan!, Complex(4, 5)) }.should raise_error(TypeError)
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path('../../fixtures/classes', __FILE__)
2
+
3
+ describe :complex_math_atan2, :shared => true do
4
+ it "returns the arc tangent of the passed arguments" do
5
+ @object.send(:atan2, 4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
6
+ @object.send(:atan2, 0.0, 1.0).should be_close(0.0, TOLERANCE)
7
+ @object.send(:atan2, -9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
8
+ @object.send(:atan2, 7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
9
+ end
10
+
11
+ it "returns the arc tangent for two Complex numbers" do
12
+ Math.atan2(Complex(3, 4), Complex(3.5, -4)).should be_close(Complex(-0.641757436698881, 1.10829873031207), TOLERANCE)
13
+ end
14
+
15
+ it "returns the arc tangent for Complex and real numbers" do
16
+ Math.atan2(Complex(3, 4), -7).should be_close(Complex(2.61576754731561, -0.494290673139855), TOLERANCE)
17
+ Math.atan2(5, Complex(3.5, -4)).should be_close(Complex(0.739102348493673, 0.487821626522923), TOLERANCE)
18
+ end
19
+ end
20
+
21
+ describe :complex_math_atan2_bang, :shared => true do
22
+ it "returns the arc tangent of the passed arguments" do
23
+ @object.send(:atan2!, 4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
24
+ @object.send(:atan2!, 0.0, 1.0).should be_close(0.0, TOLERANCE)
25
+ @object.send(:atan2!, -9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
26
+ @object.send(:atan2!, 7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
27
+ end
28
+
29
+ it "raises a TypeError when passed a Complex number" do
30
+ lambda { @object.send(:atan2!, Complex(4, 5), Complex(4, 5)) }.should raise_error(TypeError)
31
+ lambda { @object.send(:atan2!, 4, Complex(4, 5)) }.should raise_error(TypeError)
32
+ lambda { @object.send(:atan2!, Complex(4, 5), 5) }.should raise_error(TypeError)
33
+ end
34
+ end