rubysl-complex 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/complex.rb +1 -0
- data/lib/rubysl/complex.rb +2 -0
- data/lib/rubysl/complex/complex.rb +659 -0
- data/lib/rubysl/complex/version.rb +5 -0
- data/rubysl-complex.gemspec +23 -0
- data/spec/Complex_spec.rb +9 -0
- data/spec/abs2_spec.rb +10 -0
- data/spec/abs_spec.rb +10 -0
- data/spec/angle_spec.rb +7 -0
- data/spec/arg_spec.rb +7 -0
- data/spec/coerce_spec.rb +11 -0
- data/spec/comparison_spec.rb +23 -0
- data/spec/conj_spec.rb +7 -0
- data/spec/conjugate_spec.rb +7 -0
- data/spec/constants_spec.rb +9 -0
- data/spec/denominator_spec.rb +20 -0
- data/spec/divide_spec.rb +9 -0
- data/spec/equal_value_spec.rb +9 -0
- data/spec/exponent_spec.rb +10 -0
- data/spec/float/angle_spec.rb +9 -0
- data/spec/float/arg_spec.rb +9 -0
- data/spec/generic_spec.rb +25 -0
- data/spec/hash_spec.rb +10 -0
- data/spec/imag_spec.rb +10 -0
- data/spec/image_spec.rb +7 -0
- data/spec/inspect_spec.rb +10 -0
- data/spec/math/acos_spec.rb +30 -0
- data/spec/math/acosh_spec.rb +30 -0
- data/spec/math/asin_spec.rb +30 -0
- data/spec/math/asinh_spec.rb +30 -0
- data/spec/math/atan2_spec.rb +30 -0
- data/spec/math/atan_spec.rb +30 -0
- data/spec/math/atanh_spec.rb +34 -0
- data/spec/math/cos_spec.rb +30 -0
- data/spec/math/cosh_spec.rb +30 -0
- data/spec/math/exp_spec.rb +30 -0
- data/spec/math/fixtures/classes.rb +3 -0
- data/spec/math/log10_spec.rb +30 -0
- data/spec/math/log_spec.rb +30 -0
- data/spec/math/shared/acos.rb +41 -0
- data/spec/math/shared/acosh.rb +37 -0
- data/spec/math/shared/asin.rb +47 -0
- data/spec/math/shared/asinh.rb +32 -0
- data/spec/math/shared/atan.rb +32 -0
- data/spec/math/shared/atan2.rb +34 -0
- data/spec/math/shared/atanh.rb +30 -0
- data/spec/math/shared/cos.rb +30 -0
- data/spec/math/shared/cosh.rb +28 -0
- data/spec/math/shared/exp.rb +28 -0
- data/spec/math/shared/log.rb +39 -0
- data/spec/math/shared/log10.rb +41 -0
- data/spec/math/shared/sin.rb +30 -0
- data/spec/math/shared/sinh.rb +28 -0
- data/spec/math/shared/sqrt.rb +34 -0
- data/spec/math/shared/tan.rb +28 -0
- data/spec/math/shared/tanh.rb +32 -0
- data/spec/math/sin_spec.rb +30 -0
- data/spec/math/sinh_spec.rb +30 -0
- data/spec/math/sqrt_spec.rb +30 -0
- data/spec/math/tan_spec.rb +30 -0
- data/spec/math/tanh_spec.rb +30 -0
- data/spec/minus_spec.rb +9 -0
- data/spec/modulo_spec.rb +29 -0
- data/spec/multiply_spec.rb +9 -0
- data/spec/new_spec.rb +41 -0
- data/spec/numerator_spec.rb +12 -0
- data/spec/numeric/angle_spec.rb +11 -0
- data/spec/numeric/arg_spec.rb +11 -0
- data/spec/numeric/conj_spec.rb +11 -0
- data/spec/numeric/conjugate_spec.rb +11 -0
- data/spec/numeric/im_spec.rb +9 -0
- data/spec/numeric/imag_spec.rb +11 -0
- data/spec/numeric/image_spec.rb +11 -0
- data/spec/numeric/polar_spec.rb +11 -0
- data/spec/numeric/real_spec.rb +11 -0
- data/spec/plus_spec.rb +9 -0
- data/spec/polar_spec.rb +13 -0
- data/spec/real_spec.rb +10 -0
- data/spec/to_s_spec.rb +9 -0
- metadata +259 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_atanh_complex, :shared => true do
|
4
|
+
it "returns the inverse hyperbolic tangent as a Complex number for arguments greater than 1.0" do
|
5
|
+
value = Complex(18.36840028483855, 1.5707963267948966)
|
6
|
+
@object.send(@method, 1.0 + Float::EPSILON).should be_close(value, TOLERANCE)
|
7
|
+
|
8
|
+
value = Complex(0.100335347731076, 1.5707963267949)
|
9
|
+
@object.send(@method, 10).should be_close(value, TOLERANCE)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns the inverse hyperbolic tangent as a Complex number for arguments greater than 1.0" do
|
13
|
+
value = Complex(-18.36840028483855, 1.5707963267948966)
|
14
|
+
@object.send(@method, -1.0 - Float::EPSILON).should be_close(value, TOLERANCE)
|
15
|
+
|
16
|
+
value = Complex(0.100335347731076, 1.5707963267949)
|
17
|
+
@object.send(@method, 10).should be_close(value, TOLERANCE)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns the inverse hyperbolic tangent for Complex numbers" do
|
21
|
+
value = Complex(0.117500907311434, 1.40992104959658)
|
22
|
+
@object.send(@method, Complex(3, 4)).should be_close(value, TOLERANCE)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe :complex_math_atanh_no_complex, :shared => true do
|
27
|
+
it "raises a TypeError when passed a Complex number" do
|
28
|
+
lambda { @object.send(:atanh!, Complex(4, 5)) }.should raise_error(TypeError)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_cos, :shared => true do
|
4
|
+
it "returns the cosine of the argument expressed in radians" do
|
5
|
+
@object.send(:cos, Math::PI).should be_close(-1.0, TOLERANCE)
|
6
|
+
@object.send(:cos, 0).should be_close(1.0, TOLERANCE)
|
7
|
+
@object.send(:cos, Math::PI/2).should be_close(0.0, TOLERANCE)
|
8
|
+
@object.send(:cos, 3*Math::PI/2).should be_close(0.0, TOLERANCE)
|
9
|
+
@object.send(:cos, 2*Math::PI).should be_close(1.0, TOLERANCE)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns the cosine for Complex numbers" do
|
13
|
+
@object.send(:cos, Complex(0, Math::PI)).should be_close(Complex(11.5919532755215, 0.0), TOLERANCE)
|
14
|
+
@object.send(:cos, Complex(3, 4)).should be_close(Complex(-27.0349456030742, -3.85115333481178), TOLERANCE)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe :complex_math_cos_bang, :shared => true do
|
19
|
+
it "returns the cosine of the argument expressed in radians" do
|
20
|
+
@object.send(:cos!, Math::PI).should be_close(-1.0, TOLERANCE)
|
21
|
+
@object.send(:cos!, 0).should be_close(1.0, TOLERANCE)
|
22
|
+
@object.send(:cos!, Math::PI/2).should be_close(0.0, TOLERANCE)
|
23
|
+
@object.send(:cos!, 3*Math::PI/2).should be_close(0.0, TOLERANCE)
|
24
|
+
@object.send(:cos!, 2*Math::PI).should be_close(1.0, TOLERANCE)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "raises a TypeError when passed a Complex number" do
|
28
|
+
lambda { @object.send(:cos!, Complex(3, 4)) }.should raise_error(TypeError)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_cosh, :shared => true do
|
4
|
+
it "returns the hyperbolic cosine of the passed argument" do
|
5
|
+
@object.send(:cosh, 0.0).should == 1.0
|
6
|
+
@object.send(:cosh, -0.0).should == 1.0
|
7
|
+
@object.send(:cosh, 1.5).should be_close(2.35240961524325, TOLERANCE)
|
8
|
+
@object.send(:cosh, -2.99).should be_close(9.96798496414416, TOLERANCE)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the hyperbolic cosine for Complex numbers" do
|
12
|
+
@object.send(:cosh, Complex(0, Math::PI)).should be_close(Complex(-1.0, 0.0), TOLERANCE)
|
13
|
+
@object.send(:cosh, Complex(3, 4)).should be_close(Complex(-6.58066304055116, -7.58155274274654), TOLERANCE)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe :complex_math_cosh_bang, :shared => true do
|
18
|
+
it "returns the hyperbolic cosine of the passed argument" do
|
19
|
+
@object.send(:cosh!, 0.0).should == 1.0
|
20
|
+
@object.send(:cosh!, -0.0).should == 1.0
|
21
|
+
@object.send(:cosh!, 1.5).should be_close(2.35240961524325, TOLERANCE)
|
22
|
+
@object.send(:cosh!, -2.99).should be_close(9.96798496414416, TOLERANCE)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises a TypeError when passed a Complex number" do
|
26
|
+
lambda { @object.send(:cosh!, Complex(4, 5)) }.should raise_error(TypeError)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_exp, :shared => true do
|
4
|
+
it "returns the base-e exponential of the passed argument" do
|
5
|
+
@object.send(:exp, 0.0).should == 1.0
|
6
|
+
@object.send(:exp, -0.0).should == 1.0
|
7
|
+
@object.send(:exp, -1.8).should be_close(0.165298888221587, TOLERANCE)
|
8
|
+
@object.send(:exp, 1.25).should be_close(3.49034295746184, TOLERANCE)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the base-e exponential for Complex numbers" do
|
12
|
+
@object.send(:exp, Complex(0, 0)).should == Complex(1.0, 0.0)
|
13
|
+
@object.send(:exp, Complex(1, 3)).should be_close(Complex(-2.69107861381979, 0.383603953541131), TOLERANCE)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe :complex_math_exp_bang, :shared => true do
|
18
|
+
it "returns the base-e exponential of the passed argument" do
|
19
|
+
@object.send(:exp!, 0.0).should == 1.0
|
20
|
+
@object.send(:exp!, -0.0).should == 1.0
|
21
|
+
@object.send(:exp!, -1.8).should be_close(0.165298888221587, TOLERANCE)
|
22
|
+
@object.send(:exp!, 1.25).should be_close(3.49034295746184, TOLERANCE)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises a TypeError when passed a Complex number" do
|
26
|
+
lambda { @object.send(:exp!, Complex(1, 3)) }.should raise_error(TypeError)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_log, :shared => true do
|
4
|
+
it "returns the natural logarithm of the passed argument" do
|
5
|
+
@object.send(:log, 0.0001).should be_close(-9.21034037197618, TOLERANCE)
|
6
|
+
@object.send(:log, 0.000000000001e-15).should be_close(-62.1697975108392, TOLERANCE)
|
7
|
+
@object.send(:log, 1).should be_close(0.0, TOLERANCE)
|
8
|
+
@object.send(:log, 10).should be_close( 2.30258509299405, TOLERANCE)
|
9
|
+
@object.send(:log, 10e15).should be_close(36.8413614879047, TOLERANCE)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns the natural logarithm for Complex numbers" do
|
13
|
+
@object.send(:log, Complex(3, 4)).should be_close(Complex(1.6094379124341, 0.927295218001612), TOLERANCE)
|
14
|
+
@object.send(:log, Complex(-3, 4)).should be_close(Complex(1.6094379124341, 2.21429743558818), TOLERANCE)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns the natural logarithm for negative numbers as a Complex number" do
|
18
|
+
@object.send(:log, -10).should be_close(Complex(2.30258509299405, 3.14159265358979), TOLERANCE)
|
19
|
+
@object.send(:log, -20).should be_close(Complex(2.99573227355399, 3.14159265358979), TOLERANCE)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe :complex_math_log_bang, :shared => true do
|
24
|
+
it "returns the natural logarithm of the argument" do
|
25
|
+
@object.send(:log!, 0.0001).should be_close(-9.21034037197618, TOLERANCE)
|
26
|
+
@object.send(:log!, 0.000000000001e-15).should be_close(-62.1697975108392, TOLERANCE)
|
27
|
+
@object.send(:log!, 1).should be_close(0.0, TOLERANCE)
|
28
|
+
@object.send(:log!, 10).should be_close( 2.30258509299405, TOLERANCE)
|
29
|
+
@object.send(:log!, 10e15).should be_close(36.8413614879047, TOLERANCE)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises an Errno::EDOM if the argument is less than 0" do
|
33
|
+
lambda { @object.send(:log!, -10) }.should raise_error(Errno::EDOM)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises a TypeError when passed a Complex number" do
|
37
|
+
lambda { @object.send(:log!, Complex(4, 5)) }.should raise_error(TypeError)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_log10, :shared => true do
|
4
|
+
it "returns the base-10 logarithm of the passed argument" do
|
5
|
+
@object.send(:log10, 0.0001).should be_close(-4.0, TOLERANCE)
|
6
|
+
@object.send(:log10, 0.000000000001e-15).should be_close(-27.0, TOLERANCE)
|
7
|
+
@object.send(:log10, 1).should be_close(0.0, TOLERANCE)
|
8
|
+
@object.send(:log10, 10).should be_close(1.0, TOLERANCE)
|
9
|
+
@object.send(:log10, 10e15).should be_close(16.0, TOLERANCE)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns the base-10 logarithm for Complex numbers" do
|
13
|
+
@object.send(:log10, Complex(3, 4)).should be_close(Complex(0.698970004336019, 0.402719196273373), TOLERANCE)
|
14
|
+
@object.send(:log10, Complex(-3, 4)).should be_close(Complex(0.698970004336019, 0.961657157568468), TOLERANCE)
|
15
|
+
end
|
16
|
+
|
17
|
+
# BUG: does not work correctly, because Math#log10
|
18
|
+
# does not check for negative values
|
19
|
+
#it "returns the base-10 logarithm for negative numbers as a Complex number" do
|
20
|
+
# @object.send(:log10, -10).should be_close(Complex(2.30258509299405, 3.14159265358979), TOLERANCE)
|
21
|
+
# @object.send(:log10, -20).should be_close(Complex(2.99573227355399, 3.14159265358979), TOLERANCE)
|
22
|
+
#end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe :complex_math_log10_bang, :shared => true do
|
26
|
+
it "returns the base-10 logarithm of the argument" do
|
27
|
+
@object.send(:log10!, 0.0001).should be_close(-4.0, TOLERANCE)
|
28
|
+
@object.send(:log10!, 0.000000000001e-15).should be_close(-27.0, TOLERANCE)
|
29
|
+
@object.send(:log10!, 1).should be_close(0.0, TOLERANCE)
|
30
|
+
@object.send(:log10!, 10).should be_close(1.0, TOLERANCE)
|
31
|
+
@object.send(:log10!, 10e15).should be_close(16.0, TOLERANCE)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises an Errno::EDOM when the passed argument is negative" do
|
35
|
+
lambda { @object.send(:log10!, -10) }.should raise_error(Errno::EDOM)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raises a TypeError when passed a Complex number" do
|
39
|
+
lambda { @object.send(:log10!, Complex(4, 5)) }.should raise_error(TypeError)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_sin, :shared => true do
|
4
|
+
it "returns the sine of the passed argument expressed in radians" do
|
5
|
+
@object.send(:sin, Math::PI).should be_close(0.0, TOLERANCE)
|
6
|
+
@object.send(:sin, 0).should be_close(0.0, TOLERANCE)
|
7
|
+
@object.send(:sin, Math::PI/2).should be_close(1.0, TOLERANCE)
|
8
|
+
@object.send(:sin, 3*Math::PI/2).should be_close(-1.0, TOLERANCE)
|
9
|
+
@object.send(:sin, 2*Math::PI).should be_close(0.0, TOLERANCE)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns the sine for Complex numbers" do
|
13
|
+
@object.send(:sin, Complex(0, Math::PI)).should be_close(Complex(0.0, 11.5487393572577), TOLERANCE)
|
14
|
+
@object.send(:sin, Complex(3, 4)).should be_close(Complex(3.85373803791938, -27.0168132580039), TOLERANCE)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe :complex_math_sin_bang, :shared => true do
|
19
|
+
it "returns the sine of the passed argument expressed in radians" do
|
20
|
+
@object.send(:sin!, Math::PI).should be_close(0.0, TOLERANCE)
|
21
|
+
@object.send(:sin!, 0).should be_close(0.0, TOLERANCE)
|
22
|
+
@object.send(:sin!, Math::PI/2).should be_close(1.0, TOLERANCE)
|
23
|
+
@object.send(:sin!, 3*Math::PI/2).should be_close(-1.0, TOLERANCE)
|
24
|
+
@object.send(:sin!, 2*Math::PI).should be_close(0.0, TOLERANCE)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "raises a TypeError when passed a Complex number" do
|
28
|
+
lambda { @object.send(:sin!, Complex(4, 5)) }.should raise_error(TypeError)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_sinh, :shared => true do
|
4
|
+
it "returns the hyperbolic sin of the argument" do
|
5
|
+
@object.send(:sinh, 0.0).should == 0.0
|
6
|
+
@object.send(:sinh, -0.0).should == 0.0
|
7
|
+
@object.send(:sinh, 1.5).should be_close(2.12927945509482, TOLERANCE)
|
8
|
+
@object.send(:sinh, -2.8).should be_close(-8.19191835423591, TOLERANCE)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the hyperbolic sin for Complex numbers" do
|
12
|
+
@object.send(:sinh, Complex(0, Math::PI)).should be_close(Complex(-0.0, 1.22464679914735e-16), TOLERANCE)
|
13
|
+
@object.send(:sinh, Complex(3, 4)).should be_close(Complex(-6.548120040911, -7.61923172032141), TOLERANCE)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe :complex_math_sinh_bang, :shared => true do
|
18
|
+
it "returns the hyperbolic sin of the argument" do
|
19
|
+
@object.send(:sinh!, 0.0).should == 0.0
|
20
|
+
@object.send(:sinh!, -0.0).should == 0.0
|
21
|
+
@object.send(:sinh!, 1.5).should be_close(2.12927945509482, TOLERANCE)
|
22
|
+
@object.send(:sinh!, -2.8).should be_close(-8.19191835423591, TOLERANCE)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises a TypeError when passed a Complex number" do
|
26
|
+
lambda { @object.send(:sinh!, Complex(4, 5)) }.should raise_error(TypeError)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_sqrt, :shared => true do
|
4
|
+
it "returns the square root for positive numbers" do
|
5
|
+
@object.send(:sqrt, 4).should == 2
|
6
|
+
@object.send(:sqrt, 19.36).should == 4.4
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the square root for negative numbers" do
|
10
|
+
@object.send(:sqrt, -4).should == Complex(0, 2.0)
|
11
|
+
@object.send(:sqrt, -19.36).should == Complex(0, 4.4)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns the square root for Complex numbers" do
|
15
|
+
@object.send(:sqrt, Complex(4, 5)).should be_close(Complex(2.2806933416653, 1.09615788950152), TOLERANCE)
|
16
|
+
@object.send(:sqrt, Complex(4, -5)).should be_close(Complex(2.2806933416653, -1.09615788950152), TOLERANCE)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe :complex_math_sqrt_bang, :shared => true do
|
21
|
+
it "returns the square root for positive numbers" do
|
22
|
+
@object.send(:sqrt!, 4).should == 2
|
23
|
+
@object.send(:sqrt!, 19.36).should == 4.4
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises Errno::EDOM when the passed argument is negative" do
|
27
|
+
lambda { @object.send(:sqrt!, -4) }.should raise_error(Errno::EDOM)
|
28
|
+
lambda { @object.send(:sqrt!, -19.36) }.should raise_error(Errno::EDOM)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "raises a TypeError when passed a Complex number" do
|
32
|
+
lambda { @object.send(:sqrt!, Complex(4, 5)) }.should raise_error(TypeError)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_tan, :shared => true do
|
4
|
+
it "returns the tangent of the argument" do
|
5
|
+
@object.send(:tan, 0.0).should == 0.0
|
6
|
+
@object.send(:tan, -0.0).should == -0.0
|
7
|
+
@object.send(:tan, 4.22).should be_close(1.86406937682395, TOLERANCE)
|
8
|
+
@object.send(:tan, -9.65).should be_close(-0.229109052606441, TOLERANCE)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the tangent for Complex numbers" do
|
12
|
+
@object.send(:tan, Complex(0, Math::PI)).should be_close(Complex(0.0, 0.99627207622075), TOLERANCE)
|
13
|
+
@object.send(:tan, Complex(3, 4)).should be_close(Complex(-0.000187346204629452, 0.999355987381473), TOLERANCE)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe :complex_math_tan_bang, :shared => true do
|
18
|
+
it "returns the tangent of the argument" do
|
19
|
+
@object.send(:tan!, 0.0).should == 0.0
|
20
|
+
@object.send(:tan!, -0.0).should == -0.0
|
21
|
+
@object.send(:tan!, 4.22).should be_close(1.86406937682395, TOLERANCE)
|
22
|
+
@object.send(:tan!, -9.65).should be_close(-0.229109052606441, TOLERANCE)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises a TypeError when passed a Complex number" do
|
26
|
+
lambda { @object.send(:tan!, Complex(4, 5)) }.should raise_error(TypeError)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe :complex_math_tanh, :shared => true do
|
4
|
+
it "returns the hyperbolic tangent of the argument" do
|
5
|
+
@object.send(:tanh, 0.0).should == 0.0
|
6
|
+
@object.send(:tanh, -0.0).should == -0.0
|
7
|
+
@object.send(:tanh, infinity_value).should == 1.0
|
8
|
+
@object.send(:tanh, -infinity_value).should == -1.0
|
9
|
+
@object.send(:tanh, 2.5).should be_close(0.98661429815143, TOLERANCE)
|
10
|
+
@object.send(:tanh, -4.892).should be_close(-0.999887314427707, TOLERANCE)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the hyperbolic tangent for Complex numbers" do
|
14
|
+
@object.send(:tanh, Complex(0, Math::PI)).should be_close(Complex(0.0, -1.22464679914735e-16), TOLERANCE)
|
15
|
+
@object.send(:tanh, Complex(3, 4)).should be_close(Complex(1.00070953606723, 0.00490825806749599), TOLERANCE)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe :complex_math_tanh_bang, :shared => true do
|
20
|
+
it "returns the hyperbolic tangent of the argument" do
|
21
|
+
@object.send(:tanh!, 0.0).should == 0.0
|
22
|
+
@object.send(:tanh!, -0.0).should == -0.0
|
23
|
+
@object.send(:tanh!, infinity_value).should == 1.0
|
24
|
+
@object.send(:tanh!, -infinity_value).should == -1.0
|
25
|
+
@object.send(:tanh!, 2.5).should be_close(0.98661429815143, TOLERANCE)
|
26
|
+
@object.send(:tanh!, -4.892).should be_close(-0.999887314427707, TOLERANCE)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "raises a TypeError when passed a Complex number" do
|
30
|
+
lambda { @object.send(:tanh!, Complex(4, 5)) }.should raise_error(TypeError)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'complex'
|
2
|
+
require File.expand_path('../shared/sin', __FILE__)
|
3
|
+
|
4
|
+
describe "Math#sin" do
|
5
|
+
it_behaves_like :complex_math_sin, :_, IncludesMath.new
|
6
|
+
|
7
|
+
it "is a private instance method" do
|
8
|
+
IncludesMath.should have_private_instance_method(:sin)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ruby_version_is ""..."1.9" do
|
13
|
+
describe "Math#sin!" do
|
14
|
+
it_behaves_like :complex_math_sin_bang, :_, IncludesMath.new
|
15
|
+
|
16
|
+
it "is a private instance method" do
|
17
|
+
IncludesMath.should have_private_instance_method(:sin!)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Math.sin" do
|
23
|
+
it_behaves_like :complex_math_sin, :_, Math
|
24
|
+
end
|
25
|
+
|
26
|
+
ruby_version_is ""..."1.9" do
|
27
|
+
describe "Math.sin!" do
|
28
|
+
it_behaves_like :complex_math_sin_bang, :_, Math
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'complex'
|
2
|
+
require File.expand_path('../shared/sinh', __FILE__)
|
3
|
+
|
4
|
+
describe "Math#sinh" do
|
5
|
+
it_behaves_like :complex_math_sinh, :_, IncludesMath.new
|
6
|
+
|
7
|
+
it "is a private instance method" do
|
8
|
+
IncludesMath.should have_private_instance_method(:sinh)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ruby_version_is ""..."1.9" do
|
13
|
+
describe "Math#sinh!" do
|
14
|
+
it_behaves_like :complex_math_sinh_bang, :_, IncludesMath.new
|
15
|
+
|
16
|
+
it "is a private instance method" do
|
17
|
+
IncludesMath.should have_private_instance_method(:sinh!)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Math.sinh" do
|
23
|
+
it_behaves_like :complex_math_sinh, :_, Math
|
24
|
+
end
|
25
|
+
|
26
|
+
ruby_version_is ""..."1.9" do
|
27
|
+
describe "Math.sinh!" do
|
28
|
+
it_behaves_like :complex_math_sinh_bang, :_, Math
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'complex'
|
2
|
+
require File.expand_path('../shared/sqrt', __FILE__)
|
3
|
+
|
4
|
+
describe "Math#sqrt" do
|
5
|
+
it_behaves_like :complex_math_sqrt, :_, IncludesMath.new
|
6
|
+
|
7
|
+
it "is a private instance method" do
|
8
|
+
IncludesMath.should have_private_instance_method(:sqrt)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ruby_version_is ""..."1.9" do
|
13
|
+
describe "Math#sqrt!" do
|
14
|
+
it_behaves_like :complex_math_sqrt_bang, :_, IncludesMath.new
|
15
|
+
|
16
|
+
it "is a private instance method" do
|
17
|
+
IncludesMath.should have_private_instance_method(:sqrt!)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Math.sqrt" do
|
23
|
+
it_behaves_like :complex_math_sqrt, :_, Math
|
24
|
+
end
|
25
|
+
|
26
|
+
ruby_version_is ""..."1.9" do
|
27
|
+
describe "Math.sqrt!" do
|
28
|
+
it_behaves_like :complex_math_sqrt_bang, :_, Math
|
29
|
+
end
|
30
|
+
end
|