Sha256: a8197018a05194ae9154856c61bc7a4031d0635064ef9f16f3f0126988c43a60

Contents?: true

Size: 975 Bytes

Versions: 3

Compression:

Stored size: 975 Bytes

Contents

require File.join(File.dirname(__FILE__), "../spec_helper.rb")

FUNCTIONS_NUM_OF_CALCULATE = 100

def check_mpc_function(arg1, error = 10e-10, &block)
  ruby_res = yield(Complex(*(arg1.map{ |a| a.to_f })))
  mpc_res = yield(MPC.new(*arg1))
  if MPC === mpc_res
    (MPFR.new(ruby_res.real) - mpc_res.real).abs.should < error
    (MPFR.new(ruby_res.imag) - mpc_res.imag).abs.should < error
  elsif MPFR === mpc_res
    (MPFR.new(ruby_res) - mpc_res).abs.should < error
  end
end

describe MPC, "when calculating some functions" do
  before(:all) do
    @prec_old = MPFR.get_default_prec
    MPFR.set_default_prec(512)
  end

  it "should be the same result as Complex class" do
    args = GenerateComplex.float_arguments(FUNCTIONS_NUM_OF_CALCULATE)
    args.each do |a|
      check_mpc_function(a) { |b| b.abs }
      check_mpc_function(a) { |b| b.arg }
      check_mpc_function(a) { |b| b.conj }
    end
  end

  after(:all) do
    MPFR.set_default_prec(@prec_old)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-mpc-0.0.9 spec/mpc/functions_spec.rb
ruby-mpc-0.0.8 spec/mpc/functions_spec.rb
ruby-mpc-0.0.7 spec/mpc/functions_spec.rb