1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Removed CMath from the ruby repository.

This commit is contained in:
Hiroshi SHIBATA 2019-09-20 12:12:37 +09:00
parent 422ae594d9
commit a3b8501614
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
43 changed files with 4 additions and 1416 deletions

3
NEWS
View file

@ -327,6 +327,9 @@ RubyGems::
=== Compatibility issues (excluding feature bug fixes)
* Removed unmaintained libraries.
* CMath
=== Stdlib compatibility issues (excluding feature bug fixes)
profile.rb, Profiler__::

View file

@ -173,9 +173,6 @@ Zachary Scott (zzak)
[lib/bundler.rb, lib/bundler/*]
Hiroshi SHIBATA (hsbt)
https://github.com/bundler/bundler
[lib/cmath.rb]
_unmaintained_
https://github.com/ruby/cmath
[lib/csv.rb]
Kenta Murata (mrkn), Kouhei Sutou (kou)
https://github.com/ruby/csv

View file

@ -72,7 +72,6 @@ WIN32OLE:: Provides an interface for OLE Automation in Ruby
== Libraries
Bundler:: Manage your Ruby application's gem dependencies
CMath:: Provides Trigonometric and Transcendental functions for complex numbers
CSV:: Provides an interface to read and write CSV files and data
E2MM:: Module for defining custom exceptions with specific messages
FileUtils:: Several file utility methods for copying, moving, removing, etc

View file

@ -1,23 +0,0 @@
# coding: utf-8
# frozen_string_literal: true
Gem::Specification.new do |spec|
spec.name = "cmath"
spec.version = "1.0.0"
spec.authors = ["Tadayoshi Funaba"]
spec.email = [nil]
spec.summary = "Provides Trigonometric and Transcendental functions for complex numbers"
spec.description = "CMath is a library that provides trigonometric and transcendental functions for complex numbers. The functions in this module accept integers, floating-point numbers or complex numbers as arguments."
spec.homepage = "https://github.com/ruby/cmath"
spec.license = "BSD-2-Clause"
spec.files = "lib/cmath.rb"
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 2.3.0"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
end

View file

@ -1,435 +0,0 @@
# frozen_string_literal: true
##
# = Trigonometric and transcendental functions for complex numbers.
#
# CMath is a library that provides trigonometric and transcendental
# functions for complex numbers. The functions in this module accept
# integers, floating-point numbers or complex numbers as arguments.
#
# Note that the selection of functions is similar, but not identical,
# to that in module math. The reason for having two modules is that
# some users aren't interested in complex numbers, and perhaps don't
# even know what they are. They would rather have Math.sqrt(-1) raise
# an exception than return a complex number.
#
# For more information you can see Complex class.
#
# == Usage
#
# To start using this library, simply require cmath library:
#
# require "cmath"
module CMath
include Math
# Backup of Math is needed because mathn.rb replaces Math with CMath.
RealMath = Math # :nodoc:
private_constant :RealMath
%w[
exp
log
log2
log10
sqrt
cbrt
sin
cos
tan
sinh
cosh
tanh
asin
acos
atan
atan2
asinh
acosh
atanh
].each do |meth|
define_method(meth + '!') do |*args, &block|
warn("CMath##{meth}! is deprecated; use CMath##{meth} or Math##{meth}", uplevel: 1) if $VERBOSE
RealMath.send(meth, *args, &block)
end
end
##
# Math::E raised to the +z+ power
#
# CMath.exp(1.i * Math::PI) #=> (-1.0+1.2246467991473532e-16i)
def exp(z)
begin
if z.real?
RealMath.exp(z)
else
ere = RealMath.exp(z.real)
Complex(ere * RealMath.cos(z.imag),
ere * RealMath.sin(z.imag))
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the natural logarithm of Complex. If a second argument is given,
# it will be the base of logarithm.
#
# CMath.log(1 + 4i) #=> (1.416606672028108+1.3258176636680326i)
# CMath.log(1 + 4i, 10) #=> (0.6152244606891369+0.5757952953408879i)
def log(z, b=::Math::E)
begin
if z.real? && z >= 0 && b >= 0
RealMath.log(z, b)
else
Complex(RealMath.log(z.abs), z.arg) / log(b)
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the base 2 logarithm of +z+
#
# CMath.log2(-1) => (0.0+4.532360141827194i)
def log2(z)
begin
if z.real? and z >= 0
RealMath.log2(z)
else
log(z) / RealMath.log(2)
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the base 10 logarithm of +z+
#
# CMath.log10(-1) #=> (0.0+1.3643763538418412i)
def log10(z)
begin
if z.real? and z >= 0
RealMath.log10(z)
else
log(z) / RealMath.log(10)
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the non-negative square root of Complex.
#
# CMath.sqrt(-1 + 0i) #=> 0.0+1.0i
def sqrt(z)
begin
if z.real?
if z < 0
Complex(0, RealMath.sqrt(-z))
else
RealMath.sqrt(z)
end
else
if z.imag < 0 ||
(z.imag == 0 && z.imag.to_s[0] == '-')
sqrt(z.conjugate).conjugate
else
r = z.abs
x = z.real
Complex(RealMath.sqrt((r + x) / 2.0), RealMath.sqrt((r - x) / 2.0))
end
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the principal value of the cube root of +z+
#
# CMath.cbrt(1 + 4i) #=> (1.449461632813119+0.6858152562177092i)
def cbrt(z)
z ** (1.0/3)
end
##
# Returns the sine of +z+, where +z+ is given in radians
#
# CMath.sin(1 + 1i) #=> (1.2984575814159773+0.6349639147847361i)
def sin(z)
begin
if z.real?
RealMath.sin(z)
else
Complex(RealMath.sin(z.real) * RealMath.cosh(z.imag),
RealMath.cos(z.real) * RealMath.sinh(z.imag))
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the cosine of +z+, where +z+ is given in radians
#
# CMath.cos(1 + 1i) #=> (0.8337300251311491-0.9888977057628651i)
def cos(z)
begin
if z.real?
RealMath.cos(z)
else
Complex(RealMath.cos(z.real) * RealMath.cosh(z.imag),
-RealMath.sin(z.real) * RealMath.sinh(z.imag))
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the tangent of +z+, where +z+ is given in radians
#
# CMath.tan(1 + 1i) #=> (0.27175258531951174+1.0839233273386943i)
def tan(z)
begin
if z.real?
RealMath.tan(z)
else
sin(z) / cos(z)
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the hyperbolic sine of +z+, where +z+ is given in radians
#
# CMath.sinh(1 + 1i) #=> (0.6349639147847361+1.2984575814159773i)
def sinh(z)
begin
if z.real?
RealMath.sinh(z)
else
Complex(RealMath.sinh(z.real) * RealMath.cos(z.imag),
RealMath.cosh(z.real) * RealMath.sin(z.imag))
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the hyperbolic cosine of +z+, where +z+ is given in radians
#
# CMath.cosh(1 + 1i) #=> (0.8337300251311491+0.9888977057628651i)
def cosh(z)
begin
if z.real?
RealMath.cosh(z)
else
Complex(RealMath.cosh(z.real) * RealMath.cos(z.imag),
RealMath.sinh(z.real) * RealMath.sin(z.imag))
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the hyperbolic tangent of +z+, where +z+ is given in radians
#
# CMath.tanh(1 + 1i) #=> (1.0839233273386943+0.27175258531951174i)
def tanh(z)
begin
if z.real?
RealMath.tanh(z)
else
sinh(z) / cosh(z)
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the arc sine of +z+
#
# CMath.asin(1 + 1i) #=> (0.6662394324925153+1.0612750619050355i)
def asin(z)
begin
if z.real? and z >= -1 and z <= 1
RealMath.asin(z)
else
(-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the arc cosine of +z+
#
# CMath.acos(1 + 1i) #=> (0.9045568943023813-1.0612750619050357i)
def acos(z)
begin
if z.real? and z >= -1 and z <= 1
RealMath.acos(z)
else
(-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
end
rescue NoMethodError
handle_no_method_error
end
end
##
# Returns the arc tangent of +z+
#
# CMath.atan(1 + 1i) #=> (1.0172219678978514+0.4023594781085251i)
def atan(z)
begin
if z.real?
RealMath.atan(z)
else
1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
end
rescue NoMethodError
handle_no_method_error
end
end
##
# returns the arc tangent of +y+ divided by +x+ using the signs of +y+ and
# +x+ to determine the quadrant
#
# CMath.atan2(1 + 1i, 0) #=> (1.5707963267948966+0.0i)
def atan2(y,x)
begin
if y.real? and x.real?
RealMath.atan2(y,x)
else
(-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
end
rescue NoMethodError
handle_no_method_error
end
end
##
# returns the inverse hyperbolic sine of +z+
#
# CMath.asinh(1 + 1i) #=> (1.0612750619050357+0.6662394324925153i)
def asinh(z)
begin
if z.real?
RealMath.asinh(z)
else
log(z + sqrt(1.0 + z * z))
end
rescue NoMethodError
handle_no_method_error
end
end
##
# returns the inverse hyperbolic cosine of +z+
#
# CMath.acosh(1 + 1i) #=> (1.0612750619050357+0.9045568943023813i)
def acosh(z)
begin
if z.real? and z >= 1
RealMath.acosh(z)
else
log(z + sqrt(z * z - 1.0))
end
rescue NoMethodError
handle_no_method_error
end
end
##
# returns the inverse hyperbolic tangent of +z+
#
# CMath.atanh(1 + 1i) #=> (0.4023594781085251+1.0172219678978514i)
def atanh(z)
begin
if z.real? and z >= -1 and z <= 1
RealMath.atanh(z)
else
log((1.0 + z) / (1.0 - z)) / 2.0
end
rescue NoMethodError
handle_no_method_error
end
end
module_function :exp!
module_function :exp
module_function :log!
module_function :log
module_function :log2!
module_function :log2
module_function :log10!
module_function :log10
module_function :sqrt!
module_function :sqrt
module_function :cbrt!
module_function :cbrt
module_function :sin!
module_function :sin
module_function :cos!
module_function :cos
module_function :tan!
module_function :tan
module_function :sinh!
module_function :sinh
module_function :cosh!
module_function :cosh
module_function :tanh!
module_function :tanh
module_function :asin!
module_function :asin
module_function :acos!
module_function :acos
module_function :atan!
module_function :atan
module_function :atan2!
module_function :atan2
module_function :asinh!
module_function :asinh
module_function :acosh!
module_function :acosh
module_function :atanh!
module_function :atanh
module_function :frexp
module_function :ldexp
module_function :hypot
module_function :erf
module_function :erfc
module_function :gamma
module_function :lgamma
private
def handle_no_method_error # :nodoc:
if $!.name == :real?
raise TypeError, "Numeric Number required"
else
raise
end
end
module_function :handle_no_method_error
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/acos'
describe "Math#acos" do
it_behaves_like :complex_math_acos, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:acos)
end
end
describe "Math.acos" do
it_behaves_like :complex_math_acos, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/acosh'
describe "Math#acosh" do
it_behaves_like :complex_math_acosh, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:acosh)
end
end
describe "Math.acosh" do
it_behaves_like :complex_math_acosh, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/asin'
describe "Math#asin" do
it_behaves_like :complex_math_asin, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:asin)
end
end
describe "Math.asin" do
it_behaves_like :complex_math_asin, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/asinh'
describe "Math#asinh" do
it_behaves_like :complex_math_asinh, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:asinh)
end
end
describe "Math.asinh" do
it_behaves_like :complex_math_asinh, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/atan2'
describe "Math#atan2" do
it_behaves_like :complex_math_atan2, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:atan2)
end
end
describe "Math.atan2" do
it_behaves_like :complex_math_atan2, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/atan'
describe "Math#atan" do
it_behaves_like :complex_math_atan, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:atan)
end
end
describe "Math.atan" do
it_behaves_like :complex_math_atan, :_, CMath
end

View file

@ -1,17 +0,0 @@
require 'complex'
require_relative '../../../spec_helper'
require_relative '../../../fixtures/math/common'
require_relative '../../../shared/math/atanh'
require_relative 'shared/atanh'
describe "Math#atanh" do
it_behaves_like :math_atanh_base, :atanh, IncludesMath.new
it_behaves_like :complex_math_atanh_complex, :atanh, IncludesMath.new
it_behaves_like :math_atanh_private, :atanh, IncludesMath.new
end
describe "Math.atanh" do
it_behaves_like :math_atanh_base, :atanh, CMath
it_behaves_like :complex_math_atanh_complex, :atanh, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/cos'
describe "Math#cos" do
it_behaves_like :complex_math_cos, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:cos)
end
end
describe "Math.cos" do
it_behaves_like :complex_math_cos, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/cosh'
describe "Math#cosh" do
it_behaves_like :complex_math_cosh, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:cosh)
end
end
describe "Math.cosh" do
it_behaves_like :complex_math_cosh, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/exp'
describe "Math#exp" do
it_behaves_like :complex_math_exp, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:exp)
end
end
describe "Math.exp" do
it_behaves_like :complex_math_exp, :_, CMath
end

View file

@ -1,4 +0,0 @@
require 'cmath'
class IncludesMath
include CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/log10'
describe "Math#log10" do
it_behaves_like :complex_math_log10, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:log10)
end
end
describe "Math.log10" do
it_behaves_like :complex_math_log10, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/log'
describe "Math#log" do
it_behaves_like :complex_math_log, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:log)
end
end
describe "Math.log" do
it_behaves_like :complex_math_log, :_, CMath
end

View file

@ -1,41 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_acos, shared: true do
it "returns the arccosine of the passed argument" do
@object.send(:acos, 1).should be_close(0.0, TOLERANCE)
@object.send(:acos, 0).should be_close(1.5707963267949, TOLERANCE)
@object.send(:acos, -1).should be_close(Math::PI,TOLERANCE)
end
it "returns the arccosine for Complex numbers" do
@object.send(:acos, Complex(3, 4)).should be_close(Complex(0.93681246115572, -2.30550903124348), TOLERANCE)
end
it "returns the arccosine for numbers greater than 1.0 as a Complex number" do
@object.send(:acos, 1.0001).should be_close(Complex(0.0, 0.0141420177752494), TOLERANCE)
end
it "returns the arccosine for numbers less than -1.0 as a Complex number" do
@object.send(:acos, -1.0001).should be_close(Complex(3.14159265358979, -0.0141420177752495), TOLERANCE)
end
end
describe :complex_math_acos_bang, shared: true do
it "returns the arccosine of the argument" do
@object.send(:acos!, 1).should be_close(0.0, TOLERANCE)
@object.send(:acos!, 0).should be_close(1.5707963267949, TOLERANCE)
@object.send(:acos!, -1).should be_close(Math::PI,TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:acos!, Complex(4, 5)) }.should raise_error(TypeError)
end
it "raises an Errno::EDOM for numbers greater than 1.0" do
-> { @object.send(:acos!, 1.0001) }.should raise_error(Errno::EDOM)
end
it "raises an Errno::EDOM for numbers less than -1.0" do
-> { @object.send(:acos!, -1.0001) }.should raise_error(Errno::EDOM)
end
end

View file

@ -1,37 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_acosh, shared: true do
it "returns the principle value of the inverse hyperbolic cosine of the argument" do
@object.send(:acosh, 14.2).should be_close(3.345146999647, TOLERANCE)
@object.send(:acosh, 1.0).should be_close(0.0, TOLERANCE)
end
it "returns the principle value of the inverse hyperbolic cosine for numbers less than 1.0 as a Complex number" do
@object.send(:acosh, 1.0 - TOLERANCE).should be_close(Complex(0.0, 0.00774598605746135), TOLERANCE)
@object.send(:acosh, 0).should be_close(Complex(0.0, 1.5707963267949), TOLERANCE)
@object.send(:acosh, -1.0).should be_close(Complex(0.0, 3.14159265358979), TOLERANCE)
end
it "returns the principle value of the inverse hyperbolic cosine for Complex numbers" do
@object.send(:acosh, Complex(3, 4))
@object.send(:acosh, Complex(3, 4)).imaginary.should be_close(0.93681246115572, TOLERANCE)
@object.send(:acosh, Complex(3, 4)).real.should be_close(2.305509031243477, TOLERANCE)
end
end
describe :complex_math_acosh_bang, shared: true do
it "returns the principle value of the inverse hyperbolic cosine of the argument" do
@object.send(:acosh!, 14.2).should be_close(3.345146999647, TOLERANCE)
@object.send(:acosh!, 1.0).should be_close(0.0, TOLERANCE)
end
it "raises Errno::EDOM for numbers less than 1.0" do
-> { @object.send(:acosh!, 1.0 - TOLERANCE) }.should raise_error(Errno::EDOM)
-> { @object.send(:acosh!, 0) }.should raise_error(Errno::EDOM)
-> { @object.send(:acosh!, -1.0) }.should raise_error(Errno::EDOM)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:acosh!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,47 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_asin, shared: true do
it "returns the arcsine of the argument" do
@object.send(:asin, 1).should be_close(Math::PI/2, TOLERANCE)
@object.send(:asin, 0).should be_close(0.0, TOLERANCE)
@object.send(:asin, -1).should be_close(-Math::PI/2, TOLERANCE)
@object.send(:asin, 0.25).should be_close(0.252680255142079, TOLERANCE)
@object.send(:asin, 0.50).should be_close(0.523598775598299, TOLERANCE)
@object.send(:asin, 0.75).should be_close(0.8480620789814816,TOLERANCE)
end
it "returns the arcsine for Complex numbers" do
@object.send(:asin, Complex(3, 4)).should be_close(Complex(0.633983865639174, 2.30550903124347), TOLERANCE)
end
it "returns a Complex number when the argument is greater than 1.0" do
@object.send(:asin, 1.0001).should be_close(Complex(1.5707963267949, -0.0141420177752494), TOLERANCE)
end
it "returns a Complex number when the argument is less than -1.0" do
@object.send(:asin, -1.0001).should be_close(Complex(-1.5707963267949, 0.0141420177752494), TOLERANCE)
end
end
describe :complex_math_asin_bang, shared: true do
it "returns the arcsine of the argument" do
@object.send(:asin!, 1).should be_close(Math::PI/2, TOLERANCE)
@object.send(:asin!, 0).should be_close(0.0, TOLERANCE)
@object.send(:asin!, -1).should be_close(-Math::PI/2, TOLERANCE)
@object.send(:asin!, 0.25).should be_close(0.252680255142079, TOLERANCE)
@object.send(:asin!, 0.50).should be_close(0.523598775598299, TOLERANCE)
@object.send(:asin!, 0.75).should be_close(0.8480620789814816,TOLERANCE)
end
it "raises an Errno::EDOM if the argument is greater than 1.0" do
-> { @object.send(:asin!, 1.0001) }.should raise_error( Errno::EDOM)
end
it "raises an Errno::EDOM if the argument is less than -1.0" do
-> { @object.send(:asin!, -1.0001) }.should raise_error( Errno::EDOM)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:asin!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,32 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_asinh, shared: true do
it "returns the inverse hyperbolic sin of the argument" do
@object.send(:asinh, 1.5).should be_close(1.19476321728711, TOLERANCE)
@object.send(:asinh, -2.97).should be_close(-1.8089166921397, TOLERANCE)
@object.send(:asinh, 0.0).should == 0.0
@object.send(:asinh, -0.0).should == -0.0
@object.send(:asinh, 1.05367e-08).should be_close(1.05367e-08, TOLERANCE)
@object.send(:asinh, -1.05367e-08).should be_close(-1.05367e-08, TOLERANCE)
end
it "returns the inverse hyperbolic sin for Complex numbers" do
@object.send(:asinh, Complex(3, 4)).should be_close(Complex(2.29991404087927, 0.917616853351479), TOLERANCE)
@object.send(:asinh, Complex(3.5, -4)).should be_close(Complex(2.36263337274419, -0.843166327537659), TOLERANCE)
end
end
describe :complex_math_asinh_bang, shared: true do
it "returns the inverse hyperbolic sin of the argument" do
@object.send(:asinh!, 1.5).should be_close(1.19476321728711, TOLERANCE)
@object.send(:asinh!, -2.97).should be_close(-1.8089166921397, TOLERANCE)
@object.send(:asinh!, 0.0).should == 0.0
@object.send(:asinh!, -0.0).should == -0.0
@object.send(:asinh!, 1.05367e-08).should be_close(1.05367e-08, TOLERANCE)
@object.send(:asinh!, -1.05367e-08).should be_close(-1.05367e-08, TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:asinh!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,32 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_atan, shared: true do
it "returns the arctangent of the argument" do
@object.send(:atan, 1).should be_close(Math::PI/4, TOLERANCE)
@object.send(:atan, 0).should be_close(0.0, TOLERANCE)
@object.send(:atan, -1).should be_close(-Math::PI/4, TOLERANCE)
@object.send(:atan, 0.25).should be_close(0.244978663126864, TOLERANCE)
@object.send(:atan, 0.50).should be_close(0.463647609000806, TOLERANCE)
@object.send(:atan, 0.75).should be_close(0.643501108793284, TOLERANCE)
end
it "returns the arctangent for Complex numbers" do
@object.send(:atan, Complex(3, 4)).should be_close(Complex(1.44830699523146, 0.158997191679999), TOLERANCE)
@object.send(:atan, Complex(3.5, -4)).should be_close(Complex(1.44507428165589, -0.140323762363786), TOLERANCE)
end
end
describe :complex_math_atan_bang, shared: true do
it "returns the arctangent of the argument" do
@object.send(:atan!, 1).should be_close(Math::PI/4, TOLERANCE)
@object.send(:atan!, 0).should be_close(0.0, TOLERANCE)
@object.send(:atan!, -1).should be_close(-Math::PI/4, TOLERANCE)
@object.send(:atan!, 0.25).should be_close(0.244978663126864, TOLERANCE)
@object.send(:atan!, 0.50).should be_close(0.463647609000806, TOLERANCE)
@object.send(:atan!, 0.75).should be_close(0.643501108793284, TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:atan!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,34 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_atan2, shared: true do
it "returns the arc tangent of the passed arguments" do
@object.send(:atan2, 4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
@object.send(:atan2, 0.0, 1.0).should be_close(0.0, TOLERANCE)
@object.send(:atan2, -9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
@object.send(:atan2, 7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
end
it "returns the arc tangent for two Complex numbers" do
CMath.atan2(Complex(3, 4), Complex(3.5, -4)).should be_close(Complex(-0.641757436698881, 1.10829873031207), TOLERANCE)
end
it "returns the arc tangent for Complex and real numbers" do
CMath.atan2(Complex(3, 4), -7).should be_close(Complex(2.61576754731561, -0.494290673139855), TOLERANCE)
CMath.atan2(5, Complex(3.5, -4)).should be_close(Complex(0.739102348493673, 0.487821626522923), TOLERANCE)
end
end
describe :complex_math_atan2_bang, shared: true do
it "returns the arc tangent of the passed arguments" do
@object.send(:atan2!, 4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
@object.send(:atan2!, 0.0, 1.0).should be_close(0.0, TOLERANCE)
@object.send(:atan2!, -9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
@object.send(:atan2!, 7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:atan2!, Complex(4, 5), Complex(4, 5)) }.should raise_error(TypeError)
-> { @object.send(:atan2!, 4, Complex(4, 5)) }.should raise_error(TypeError)
-> { @object.send(:atan2!, Complex(4, 5), 5) }.should raise_error(TypeError)
end
end

View file

@ -1,30 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_atanh_complex, shared: true do
it "returns the inverse hyperbolic tangent as a Complex number for arguments greater than 1.0" do
value = Complex(18.36840028483855, 1.5707963267948966)
@object.send(@method, 1.0 + Float::EPSILON).should be_close(value, TOLERANCE)
value = Complex(0.100335347731076, 1.5707963267949)
@object.send(@method, 10).should be_close(value, TOLERANCE)
end
it "returns the inverse hyperbolic tangent as a Complex number for arguments greater than 1.0" do
value = Complex(-18.36840028483855, 1.5707963267948966)
@object.send(@method, -1.0 - Float::EPSILON).should be_close(value, TOLERANCE)
value = Complex(0.100335347731076, 1.5707963267949)
@object.send(@method, 10).should be_close(value, TOLERANCE)
end
it "returns the inverse hyperbolic tangent for Complex numbers" do
value = Complex(0.117500907311434, 1.40992104959658)
@object.send(@method, Complex(3, 4)).should be_close(value, TOLERANCE)
end
end
describe :complex_math_atanh_no_complex, shared: true do
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:atanh!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,30 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_cos, shared: true do
it "returns the cosine of the argument expressed in radians" do
@object.send(:cos, CMath::PI).should be_close(-1.0, TOLERANCE)
@object.send(:cos, 0).should be_close(1.0, TOLERANCE)
@object.send(:cos, CMath::PI/2).should be_close(0.0, TOLERANCE)
@object.send(:cos, 3*Math::PI/2).should be_close(0.0, TOLERANCE)
@object.send(:cos, 2*Math::PI).should be_close(1.0, TOLERANCE)
end
it "returns the cosine for Complex numbers" do
@object.send(:cos, Complex(0, CMath::PI)).should be_close(Complex(11.5919532755215, 0.0), TOLERANCE)
@object.send(:cos, Complex(3, 4)).should be_close(Complex(-27.0349456030742, -3.85115333481178), TOLERANCE)
end
end
describe :complex_math_cos_bang, shared: true do
it "returns the cosine of the argument expressed in radians" do
@object.send(:cos!, CMath::PI).should be_close(-1.0, TOLERANCE)
@object.send(:cos!, 0).should be_close(1.0, TOLERANCE)
@object.send(:cos!, CMath::PI/2).should be_close(0.0, TOLERANCE)
@object.send(:cos!, 3*Math::PI/2).should be_close(0.0, TOLERANCE)
@object.send(:cos!, 2*Math::PI).should be_close(1.0, TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:cos!, Complex(3, 4)) }.should raise_error(TypeError)
end
end

View file

@ -1,28 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_cosh, shared: true do
it "returns the hyperbolic cosine of the passed argument" do
@object.send(:cosh, 0.0).should == 1.0
@object.send(:cosh, -0.0).should == 1.0
@object.send(:cosh, 1.5).should be_close(2.35240961524325, TOLERANCE)
@object.send(:cosh, -2.99).should be_close(9.96798496414416, TOLERANCE)
end
it "returns the hyperbolic cosine for Complex numbers" do
@object.send(:cosh, Complex(0, CMath::PI)).should be_close(Complex(-1.0, 0.0), TOLERANCE)
@object.send(:cosh, Complex(3, 4)).should be_close(Complex(-6.58066304055116, -7.58155274274654), TOLERANCE)
end
end
describe :complex_math_cosh_bang, shared: true do
it "returns the hyperbolic cosine of the passed argument" do
@object.send(:cosh!, 0.0).should == 1.0
@object.send(:cosh!, -0.0).should == 1.0
@object.send(:cosh!, 1.5).should be_close(2.35240961524325, TOLERANCE)
@object.send(:cosh!, -2.99).should be_close(9.96798496414416, TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:cosh!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,28 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_exp, shared: true do
it "returns the base-e exponential of the passed argument" do
@object.send(:exp, 0.0).should == 1.0
@object.send(:exp, -0.0).should == 1.0
@object.send(:exp, -1.8).should be_close(0.165298888221587, TOLERANCE)
@object.send(:exp, 1.25).should be_close(3.49034295746184, TOLERANCE)
end
it "returns the base-e exponential for Complex numbers" do
@object.send(:exp, Complex(0, 0)).should == Complex(1.0, 0.0)
@object.send(:exp, Complex(1, 3)).should be_close(Complex(-2.69107861381979, 0.383603953541131), TOLERANCE)
end
end
describe :complex_math_exp_bang, shared: true do
it "returns the base-e exponential of the passed argument" do
@object.send(:exp!, 0.0).should == 1.0
@object.send(:exp!, -0.0).should == 1.0
@object.send(:exp!, -1.8).should be_close(0.165298888221587, TOLERANCE)
@object.send(:exp!, 1.25).should be_close(3.49034295746184, TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:exp!, Complex(1, 3)) }.should raise_error(TypeError)
end
end

View file

@ -1,39 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_log, shared: true do
it "returns the natural logarithm of the passed argument" do
@object.send(:log, 0.0001).should be_close(-9.21034037197618, TOLERANCE)
@object.send(:log, 0.000000000001e-15).should be_close(-62.1697975108392, TOLERANCE)
@object.send(:log, 1).should be_close(0.0, TOLERANCE)
@object.send(:log, 10).should be_close( 2.30258509299405, TOLERANCE)
@object.send(:log, 10e15).should be_close(36.8413614879047, TOLERANCE)
end
it "returns the natural logarithm for Complex numbers" do
@object.send(:log, Complex(3, 4)).should be_close(Complex(1.6094379124341, 0.927295218001612), TOLERANCE)
@object.send(:log, Complex(-3, 4)).should be_close(Complex(1.6094379124341, 2.21429743558818), TOLERANCE)
end
it "returns the natural logarithm for negative numbers as a Complex number" do
@object.send(:log, -10).should be_close(Complex(2.30258509299405, 3.14159265358979), TOLERANCE)
@object.send(:log, -20).should be_close(Complex(2.99573227355399, 3.14159265358979), TOLERANCE)
end
end
describe :complex_math_log_bang, shared: true do
it "returns the natural logarithm of the argument" do
@object.send(:log!, 0.0001).should be_close(-9.21034037197618, TOLERANCE)
@object.send(:log!, 0.000000000001e-15).should be_close(-62.1697975108392, TOLERANCE)
@object.send(:log!, 1).should be_close(0.0, TOLERANCE)
@object.send(:log!, 10).should be_close( 2.30258509299405, TOLERANCE)
@object.send(:log!, 10e15).should be_close(36.8413614879047, TOLERANCE)
end
it "raises an Errno::EDOM if the argument is less than 0" do
-> { @object.send(:log!, -10) }.should raise_error(Errno::EDOM)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:log!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,41 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_log10, shared: true do
it "returns the base-10 logarithm of the passed argument" do
@object.send(:log10, 0.0001).should be_close(-4.0, TOLERANCE)
@object.send(:log10, 0.000000000001e-15).should be_close(-27.0, TOLERANCE)
@object.send(:log10, 1).should be_close(0.0, TOLERANCE)
@object.send(:log10, 10).should be_close(1.0, TOLERANCE)
@object.send(:log10, 10e15).should be_close(16.0, TOLERANCE)
end
it "returns the base-10 logarithm for Complex numbers" do
@object.send(:log10, Complex(3, 4)).should be_close(Complex(0.698970004336019, 0.402719196273373), TOLERANCE)
@object.send(:log10, Complex(-3, 4)).should be_close(Complex(0.698970004336019, 0.961657157568468), TOLERANCE)
end
# BUG: does not work correctly, because Math#log10
# does not check for negative values
#it "returns the base-10 logarithm for negative numbers as a Complex number" do
# @object.send(:log10, -10).should be_close(Complex(2.30258509299405, 3.14159265358979), TOLERANCE)
# @object.send(:log10, -20).should be_close(Complex(2.99573227355399, 3.14159265358979), TOLERANCE)
#end
end
describe :complex_math_log10_bang, shared: true do
it "returns the base-10 logarithm of the argument" do
@object.send(:log10!, 0.0001).should be_close(-4.0, TOLERANCE)
@object.send(:log10!, 0.000000000001e-15).should be_close(-27.0, TOLERANCE)
@object.send(:log10!, 1).should be_close(0.0, TOLERANCE)
@object.send(:log10!, 10).should be_close(1.0, TOLERANCE)
@object.send(:log10!, 10e15).should be_close(16.0, TOLERANCE)
end
it "raises an Errno::EDOM when the passed argument is negative" do
-> { @object.send(:log10!, -10) }.should raise_error(Errno::EDOM)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:log10!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,30 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_sin, shared: true do
it "returns the sine of the passed argument expressed in radians" do
@object.send(:sin, CMath::PI).should be_close(0.0, TOLERANCE)
@object.send(:sin, 0).should be_close(0.0, TOLERANCE)
@object.send(:sin, CMath::PI/2).should be_close(1.0, TOLERANCE)
@object.send(:sin, 3*Math::PI/2).should be_close(-1.0, TOLERANCE)
@object.send(:sin, 2*Math::PI).should be_close(0.0, TOLERANCE)
end
it "returns the sine for Complex numbers" do
@object.send(:sin, Complex(0, CMath::PI)).should be_close(Complex(0.0, 11.5487393572577), TOLERANCE)
@object.send(:sin, Complex(3, 4)).should be_close(Complex(3.85373803791938, -27.0168132580039), TOLERANCE)
end
end
describe :complex_math_sin_bang, shared: true do
it "returns the sine of the passed argument expressed in radians" do
@object.send(:sin!, CMath::PI).should be_close(0.0, TOLERANCE)
@object.send(:sin!, 0).should be_close(0.0, TOLERANCE)
@object.send(:sin!, CMath::PI/2).should be_close(1.0, TOLERANCE)
@object.send(:sin!, 3*Math::PI/2).should be_close(-1.0, TOLERANCE)
@object.send(:sin!, 2*Math::PI).should be_close(0.0, TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:sin!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,28 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_sinh, shared: true do
it "returns the hyperbolic sin of the argument" do
@object.send(:sinh, 0.0).should == 0.0
@object.send(:sinh, -0.0).should == 0.0
@object.send(:sinh, 1.5).should be_close(2.12927945509482, TOLERANCE)
@object.send(:sinh, -2.8).should be_close(-8.19191835423591, TOLERANCE)
end
it "returns the hyperbolic sin for Complex numbers" do
@object.send(:sinh, Complex(0, CMath::PI)).should be_close(Complex(-0.0, 1.22464679914735e-16), TOLERANCE)
@object.send(:sinh, Complex(3, 4)).should be_close(Complex(-6.548120040911, -7.61923172032141), TOLERANCE)
end
end
describe :complex_math_sinh_bang, shared: true do
it "returns the hyperbolic sin of the argument" do
@object.send(:sinh!, 0.0).should == 0.0
@object.send(:sinh!, -0.0).should == 0.0
@object.send(:sinh!, 1.5).should be_close(2.12927945509482, TOLERANCE)
@object.send(:sinh!, -2.8).should be_close(-8.19191835423591, TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:sinh!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,34 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_sqrt, shared: true do
it "returns the square root for positive numbers" do
@object.send(:sqrt, 4).should == 2
@object.send(:sqrt, 19.36).should == 4.4
end
it "returns the square root for negative numbers" do
@object.send(:sqrt, -4).should == Complex(0, 2.0)
@object.send(:sqrt, -19.36).should == Complex(0, 4.4)
end
it "returns the square root for Complex numbers" do
@object.send(:sqrt, Complex(4, 5)).should be_close(Complex(2.2806933416653, 1.09615788950152), TOLERANCE)
@object.send(:sqrt, Complex(4, -5)).should be_close(Complex(2.2806933416653, -1.09615788950152), TOLERANCE)
end
end
describe :complex_math_sqrt_bang, shared: true do
it "returns the square root for positive numbers" do
@object.send(:sqrt!, 4).should == 2
@object.send(:sqrt!, 19.36).should == 4.4
end
it "raises Errno::EDOM when the passed argument is negative" do
-> { @object.send(:sqrt!, -4) }.should raise_error(Errno::EDOM)
-> { @object.send(:sqrt!, -19.36) }.should raise_error(Errno::EDOM)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:sqrt!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,28 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_tan, shared: true do
it "returns the tangent of the argument" do
@object.send(:tan, 0.0).should == 0.0
@object.send(:tan, -0.0).should == -0.0
@object.send(:tan, 4.22).should be_close(1.86406937682395, TOLERANCE)
@object.send(:tan, -9.65).should be_close(-0.229109052606441, TOLERANCE)
end
it "returns the tangent for Complex numbers" do
@object.send(:tan, Complex(0, CMath::PI)).should be_close(Complex(0.0, 0.99627207622075), TOLERANCE)
@object.send(:tan, Complex(3, 4)).should be_close(Complex(-0.000187346204629452, 0.999355987381473), TOLERANCE)
end
end
describe :complex_math_tan_bang, shared: true do
it "returns the tangent of the argument" do
@object.send(:tan!, 0.0).should == 0.0
@object.send(:tan!, -0.0).should == -0.0
@object.send(:tan!, 4.22).should be_close(1.86406937682395, TOLERANCE)
@object.send(:tan!, -9.65).should be_close(-0.229109052606441, TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:tan!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,32 +0,0 @@
require_relative '../fixtures/classes'
describe :complex_math_tanh, shared: true do
it "returns the hyperbolic tangent of the argument" do
@object.send(:tanh, 0.0).should == 0.0
@object.send(:tanh, -0.0).should == -0.0
@object.send(:tanh, infinity_value).should == 1.0
@object.send(:tanh, -infinity_value).should == -1.0
@object.send(:tanh, 2.5).should be_close(0.98661429815143, TOLERANCE)
@object.send(:tanh, -4.892).should be_close(-0.999887314427707, TOLERANCE)
end
it "returns the hyperbolic tangent for Complex numbers" do
@object.send(:tanh, Complex(0, CMath::PI)).should be_close(Complex(0.0, -1.22464679914735e-16), TOLERANCE)
@object.send(:tanh, Complex(3, 4)).should be_close(Complex(1.00070953606723, 0.00490825806749599), TOLERANCE)
end
end
describe :complex_math_tanh_bang, shared: true do
it "returns the hyperbolic tangent of the argument" do
@object.send(:tanh!, 0.0).should == 0.0
@object.send(:tanh!, -0.0).should == -0.0
@object.send(:tanh!, infinity_value).should == 1.0
@object.send(:tanh!, -infinity_value).should == -1.0
@object.send(:tanh!, 2.5).should be_close(0.98661429815143, TOLERANCE)
@object.send(:tanh!, -4.892).should be_close(-0.999887314427707, TOLERANCE)
end
it "raises a TypeError when passed a Complex number" do
-> { @object.send(:tanh!, Complex(4, 5)) }.should raise_error(TypeError)
end
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/sin'
describe "Math#sin" do
it_behaves_like :complex_math_sin, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:sin)
end
end
describe "Math.sin" do
it_behaves_like :complex_math_sin, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/sinh'
describe "Math#sinh" do
it_behaves_like :complex_math_sinh, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:sinh)
end
end
describe "Math.sinh" do
it_behaves_like :complex_math_sinh, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/sqrt'
describe "Math#sqrt" do
it_behaves_like :complex_math_sqrt, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:sqrt)
end
end
describe "Math.sqrt" do
it_behaves_like :complex_math_sqrt, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/tan'
describe "Math#tan" do
it_behaves_like :complex_math_tan, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:tan)
end
end
describe "Math.tan" do
it_behaves_like :complex_math_tan, :_, CMath
end

View file

@ -1,15 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'
require_relative 'shared/tanh'
describe "Math#tanh" do
it_behaves_like :complex_math_tanh, :_, IncludesMath.new
it "is a private instance method" do
IncludesMath.should have_private_instance_method(:tanh)
end
end
describe "Math.tanh" do
it_behaves_like :complex_math_tanh, :_, CMath
end

View file

@ -1,3 +0,0 @@
require_relative '../../../spec_helper'
require 'complex'

View file

@ -1,116 +0,0 @@
# frozen_string_literal: true
require 'test/unit'
require 'cmath'
class TestCMath < Test::Unit::TestCase
def test_deprecated_method
root = nil
assert_warning(/CMath#sqrt! is deprecated; use CMath#sqrt or Math#sqrt/) do
root = CMath.sqrt!(1)
end
assert_equal CMath.sqrt(1), root
end
def test_sqrt
assert_equal 1, CMath.sqrt(1)
assert_equal CMath.sqrt(1i), CMath.sqrt(1.0i), '[ruby-core:31672]'
assert_equal Complex(0,2), CMath.sqrt(-4.0)
assert_equal Complex(0,2), CMath.sqrt(-4)
assert_equal Complex(0,2), CMath.sqrt(Rational(-4))
assert_equal Complex(0,3), CMath.sqrt(-9.0)
assert_equal Complex(0,3), CMath.sqrt(-9)
assert_equal Complex(0,3), CMath.sqrt(Rational(-9))
assert_in_delta (1.272019649514069+0.7861513777574233i), CMath.sqrt(1+2i)
assert_in_delta 3.0i, CMath.sqrt(-9)
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.sqrt("1") }
end
def test_log
assert_in_delta (0.8047189562170503+1.1071487177940904i), CMath.log(1+2i)
assert_in_delta (0.7324867603589635+1.0077701926457874i), CMath.log(1+2i,3)
assert_in_delta Math::PI*1i , CMath.log(-1)
assert_in_delta 3.0 , CMath.log(8, 2)
assert_in_delta (1.092840647090816-0.42078724841586035i), CMath.log(-8, -2)
end
def test_trigonometric_functions
assert_equal 0, CMath.asin(0)
assert_equal 0, CMath.acos(1)
assert_equal 0, CMath.atan(0)
assert_equal 0, CMath.asinh(0)
assert_equal 0, CMath.acosh(1)
assert_equal 0, CMath.atanh(0)
assert_in_delta CMath.sinh(2).i, CMath.sin(2i)
assert_in_delta CMath.cosh(2), CMath.cos(2i)
assert_in_delta CMath.tanh(2).i, CMath.tan(2i)
assert_in_delta CMath.sin(2).i, CMath.sinh(2i)
assert_in_delta CMath.cos(2), CMath.cosh(2i)
assert_in_delta CMath.tan(2).i, CMath.tanh(2i)
assert_in_delta 1+1i, CMath.sin(CMath.asin(1+1i))
assert_in_delta 1+1i, CMath.cos(CMath.acos(1+1i))
assert_in_delta 1+1i, CMath.tan(CMath.atan(1+1i))
assert_in_delta 1+1i, CMath.sinh(CMath.asinh(1+1i))
assert_in_delta 1+1i, CMath.cosh(CMath.acosh(1+1i))
assert_in_delta 1+1i, CMath.tanh(CMath.atanh(1+1i))
assert_in_delta (3.165778513216168+1.959601041421606i), CMath.sin(1+2i)
assert_in_delta (2.0327230070196656-3.0518977991517997i), CMath.cos(1+2i)
assert_in_delta (0.033812826079896774+1.0147936161466338i), CMath.tan(1+2i)
assert_in_delta (-0.4890562590412937+1.4031192506220405i), CMath.sinh(1+2i)
assert_in_delta (-0.64214812471552+1.0686074213827783i), CMath.cosh(1+2i)
assert_in_delta (1.16673625724092-0.2434582011857252i), CMath.tanh(1+2i)
assert_in_delta (0.4270785863924755+1.5285709194809978i), CMath.asin(1+2i)
assert_in_delta (1.1437177404024204-1.528570919480998i), CMath.acos(1+2i)
assert_in_delta (1.3389725222944935+0.4023594781085251i), CMath.atan(1+2i)
assert_in_delta (1.4693517443681852+1.0634400235777521i), CMath.asinh(1+2i)
assert_in_delta (1.528570919480998+1.1437177404024204i), CMath.acosh(1+2i)
assert_in_delta (0.17328679513998635+1.1780972450961724i), CMath.atanh(1+2i)
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.sin("0") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.cos("0") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.tan("0") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.sinh("0") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.cosh("0") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.tanh("0") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.asin("0") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.atan("0") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.asinh("0") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.acosh("0") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.atanh("0") }
end
def test_functions
assert_equal (1), CMath.exp(0)
assert_in_delta (-1.1312043837568135+2.4717266720048188i), CMath.exp(1+2i)
assert_in_delta (-1), CMath.exp(Math::PI.i)
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.exp("0") }
assert_equal (0), CMath.log2(1)
assert_in_delta (1.1609640474436813+1.5972779646881088i), CMath.log2(1+2i)
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.log2("1") }
assert_equal (0), CMath.log10(1)
assert_in_delta (0.3494850021680094+0.480828578784234i), CMath.log10(1+2i)
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.log10("1") }
assert_equal (0), CMath.atan2(0,1)
assert_in_delta (1.3389725222944935+0.4023594781085251i), CMath.atan2(1+2i,1)
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.atan2("0", 1) }
end
def test_error_handling
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.acos("2") }
assert_raise_with_message(TypeError, "Numeric Number required") { CMath.log("2") }
assert_raise(ArgumentError) { CMath.log(2, "2") }
assert_raise(NoMethodError) { CMath.log(2, 2i) }
assert_raise(RangeError) { CMath.hypot(2i, 2i) }
end
def test_cbrt_returns_principal_value_of_cube_root
assert_equal (-8)**(1.0/3), CMath.cbrt(-8), '#3676'
end
end

View file

@ -20,7 +20,6 @@
# * https://github.com/ruby/zlib
# * https://github.com/ruby/fcntl
# * https://github.com/ruby/scanf
# * https://github.com/ruby/cmath
# * https://github.com/ruby/strscan
# * https://github.com/ruby/ipaddr
# * https://github.com/ruby/logger
@ -64,7 +63,6 @@ $repositories = {
zlib: 'ruby/zlib',
fcntl: 'ruby/fcntl',
scanf: 'ruby/scanf',
cmath: 'ruby/cmath',
strscan: 'ruby/strscan',
ipaddr: 'ruby/ipaddr',
logger: 'ruby/logger',
@ -222,7 +220,7 @@ def sync_default_gems(gem)
cp_r(Dir.glob("#{upstream}/ext/racc/cparse/*"), "ext/racc/cparse")
cp_r("#{upstream}/test", "test/racc")
`git checkout ext/racc/cparse/README`
when "rexml", "rss", "matrix", "irb", "csv", "shell", "logger", "ostruct", "scanf", "webrick", "fileutils", "forwardable", "prime", "tracer", "ipaddr", "cmath", "mutex_m", "sync"
when "rexml", "rss", "matrix", "irb", "csv", "shell", "logger", "ostruct", "scanf", "webrick", "fileutils", "forwardable", "prime", "tracer", "ipaddr", "mutex_m", "sync"
sync_lib gem
else
end