Last Modified
2010-06-22 20:46:53 +0200
Requires
  • flt/math
  • complex

Description

Complex number support for Flt::Num types.

Complex is extended to handle properly components of Num types.

Examples:

  require 'flt/complex'
  include Flt
  DecNum.context(:precision=>4) do
    puts (Complex(1,2)*DecNum(2)).abs.inspect            # => DecNum('4.472')
  end

Complex functions are provided through Num.ccontext object, Context#.cmath blocks and CMath modules.

Examples:

  require 'flt/complex'
  include Flt
  DecNum.context.precision = 10
  puts DecNum.ccontext.sqrt(-2)                           # => 0+1.414213562i
  puts DecNum.ccontext(:precision=>5).sqrt(-2)            # => 0+1.4142i
  puts DecNum.context(:precision=>6).cmath{sqrt(-2)}      # => 0+1.41421i

CMath Examples:

  DecNum.context(:precision=>5) do
    puts DecNum::CMath.sqrt(-2)                           # => 0+1.4142i
  end
  DecNum.context.precision = 10
  include DecNum::CMath
  puts sqrt(-2)                                           # => 0+1.414213562i