Parent

Class Index [+]

Quicksearch

Flt::ComplexContext

Public Class Methods

math_function(mth, negative_arg_to_complex=false, extra_prec=3, &blk) click to toggle source
     # File lib/flt/complex.rb, line 91
 91:     def self.math_function(mth, negative_arg_to_complex=false, extra_prec=3, &blk)
 92:       class_eval do
 93:         define_method mth do |*args|
 94:           is_complex = args.detect{|z| z.kind_of?(Complex)}
 95:           if is_complex || (negative_arg_to_complex && args.first<0)
 96:             num_class.context(:extra_precision=>extra_prec) do |mth|
 97:               #Complex.rectangular *blk[mth, *args].map{|v| @context.plus(v)}
 98:               Complex.rectangular *instance_exec(mth,*args,&blk).map{|v| @context.plus(v)}
 99:             end
100:           else
101:             @context.send(mth, *args) # Num(@context.send(mth, *args)) ?
102:           end
103:         end
104:       end
105:     end
new(context) click to toggle source
    # File lib/flt/complex.rb, line 67
67:     def initialize(context)
68:       @context = context
69:     end

Public Instance Methods

Num(z) click to toggle source
    # File lib/flt/complex.rb, line 79
79:     def Num(z)
80:       if z.kind_of?(Complex)
81:         Complex.rectangular(*z.rectangular.map{|v| @context.num_class[v]})
82:       else
83:         Complex.rectangular(@context.num_class[z])
84:       end
85:     end
abs(z) click to toggle source
    # File lib/flt/complex.rb, line 87
87:     def abs(z)
88:       z.abs
89:     end
acos(z) click to toggle source
     # File lib/flt/complex.rb, line 214
214:     def acos(z)
215:       z_is_complex = z.kind_of?(Complex)
216:       if z_is_complex || z.abs>1
217:         # z = Complex(1) unless z_is_complex
218:         i = Complex(0,@context.num_class[1])
219:         fix num_class.context(:extra_precision=>3).cmath {
220:           -i*ln(z + i*sqrt(1-z*z))
221:         }
222:       else
223:         @context.acos(z)
224:       end
225:     end
acosh(z) click to toggle source
     # File lib/flt/complex.rb, line 227
227:     def acosh(z)
228:       z_is_complex = z.kind_of?(Complex)
229:       if z_is_complex || z<=1
230:         # z = Complex(1) unless z_is_complex
231:         fix num_class.context(:extra_precision=>3).cmath{ ln(z + sqrt(z*z-1)) }
232:       else
233:         @context.acosh(z)
234:       end
235:     end
asin(z) click to toggle source
     # File lib/flt/complex.rb, line 201
201:     def asin(z)
202:       z_is_complex = z.kind_of?(Complex)
203:       if z_is_complex || z.abs>1
204:         # z = Complex(1) unless z_is_complex
205:         i = Complex(0,@context.num_class[1])
206:         fix num_class.context(:extra_precision=>3).cmath {
207:           -i*ln(i*z + sqrt(1-z*z))
208:         }
209:       else
210:         @context.asin(z)
211:       end
212:     end
atanh(z) click to toggle source
     # File lib/flt/complex.rb, line 237
237:     def atanh(z)
238:       z_is_complex = z.kind_of?(Complex)
239:       if z_is_complex || z.abs>1
240:         # z = Complex(1) unless z_is_complex
241:         i = Complex(0,@context.num_class[1])
242:         fix num_class.context(:extra_precision=>3).cmath{ num_class.one_half*ln((1+z)/(1-z)) }
243:       else
244:         @context.atanh(z)
245:       end
246:     end
math() click to toggle source
    # File lib/flt/complex.rb, line 75
75:     def math
76:       num_class.context
77:     end
num_class() click to toggle source
    # File lib/flt/complex.rb, line 71
71:     def num_class
72:       @context.num_class
73:     end
sqrt(z) click to toggle source
     # File lib/flt/complex.rb, line 146
146:     def sqrt(z)
147:       z_is_complex = z.kind_of?(Complex)
148:       if z_is_complex || z<0
149:         if z_is_complex
150:           re = im = nil
151:           num_class.context(:extra_precision=>3) do |mth|
152:             z = Num(z)
153:             i_sign = z.imag.sign
154:             r = abs(z)
155:             x = z.real
156:             re = ((r+x)/2).sqrt
157:             im = ((r-x)/2).sqrt.copy_sign(i_sign)
158:           end
159:           fix_rect(re, im)
160:         else
161:           Complex(0, @context.sqrt(-z))
162:         end
163:       else
164:         @context.sqrt(z)
165:       end
166:     end

Private Instance Methods

fix(z) click to toggle source
     # File lib/flt/complex.rb, line 266
266:     def fix(z)
267:       fix_rect *z.rectangular
268:     end
fix_polar(r, theta) click to toggle source
     # File lib/flt/complex.rb, line 258
258:     def fix_polar(r, theta)
259:       num_class.context(:extra_precision=>3) do |mth|
260:         re = r*mth.cos(theta)
261:         im = r*mth.sin(theta)
262:       end
263:       fix_rect(re, im)
264:     end
fix_rect(re, im) click to toggle source
     # File lib/flt/complex.rb, line 254
254:     def fix_rect(re, im)
255:       Complex(@context.plus(re), @context.plus(im))
256:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.