Module: Math

Defined in:
lib/complex.rb

Class Method Summary collapse

Class Method Details

.acos(z) ⇒ Object



566
567
568
569
570
571
572
# File 'lib/complex.rb', line 566

def acos(z)
  if Complex.generic?(z) and z >= -1 and z <= 1
    acos!(z)
  else
    -1.0.im * log( z + 1.0.im * sqrt(1.0-z*z) )
  end
end

.acos!Object



458
# File 'lib/complex.rb', line 458

alias acos! acos

.acosh(z) ⇒ Object



598
599
600
601
602
603
604
# File 'lib/complex.rb', line 598

def acosh(z)
  if Complex.generic?(z) and z >= 1
    acosh!(z)
  else
    log( z + sqrt(z*z-1.0) )
  end
end

.acosh!Object



462
# File 'lib/complex.rb', line 462

alias acosh! acosh

.asin(z) ⇒ Object



574
575
576
577
578
579
580
# File 'lib/complex.rb', line 574

def asin(z)
  if Complex.generic?(z) and z >= -1 and z <= 1
    asin!(z)
  else
    -1.0.im * log( 1.0.im * z + sqrt(1.0-z*z) )
  end
end

.asin!Object



459
# File 'lib/complex.rb', line 459

alias asin! asin

.asinh(z) ⇒ Object



606
607
608
609
610
611
612
# File 'lib/complex.rb', line 606

def asinh(z)
  if Complex.generic?(z)
    asinh!(z)
  else
    log( z + sqrt(1.0+z*z) )
  end
end

.asinh!Object



463
# File 'lib/complex.rb', line 463

alias asinh! asinh

.atan(z) ⇒ Object



582
583
584
585
586
587
588
# File 'lib/complex.rb', line 582

def atan(z)
  if Complex.generic?(z)
    atan!(z)
  else
    1.0.im * log( (1.0.im+z) / (1.0.im-z) ) / 2.0
  end
end

.atan!Object



460
# File 'lib/complex.rb', line 460

alias atan! atan

.atan2(y, x) ⇒ Object



590
591
592
593
594
595
596
# File 'lib/complex.rb', line 590

def atan2(y,x)
  if Complex.generic?(y) and Complex.generic?(x)
    atan2!(y,x)
  else
    -1.0.im * log( (x+1.0.im*y) / sqrt(x*x+y*y) )
  end
end

.atan2!Object



461
# File 'lib/complex.rb', line 461

alias atan2! atan2

.atanh(z) ⇒ Object



614
615
616
617
618
619
620
# File 'lib/complex.rb', line 614

def atanh(z)
  if Complex.generic?(z) and z >= -1 and z <= 1
    atanh!(z)
  else
    log( (1.0+z) / (1.0-z) ) / 2.0
  end
end

.atanh!Object



464
# File 'lib/complex.rb', line 464

alias atanh! atanh

.cos(z) ⇒ Object

Redefined to handle a Complex argument.



495
496
497
498
499
500
501
502
# File 'lib/complex.rb', line 495

def cos(z)
  if Complex.generic?(z)
    cos!(z)
  else
    Complex(cos!(z.real)*cosh!(z.image),
     -sin!(z.real)*sinh!(z.image))
  end
end

.cos!Object



452
# File 'lib/complex.rb', line 452

alias cos! cos

.cosh(z) ⇒ Object



531
532
533
534
535
536
537
# File 'lib/complex.rb', line 531

def cosh(z)
  if Complex.generic?(z)
    cosh!(z)
  else
    Complex( cosh!(z.real)*cos!(z.image), sinh!(z.real)*sin!(z.image) )
  end
end

.cosh!Object



455
# File 'lib/complex.rb', line 455

alias cosh! cosh

.exp(z) ⇒ Object

Redefined to handle a Complex argument.



486
487
488
489
490
491
492
# File 'lib/complex.rb', line 486

def exp(z)
  if Complex.generic?(z)
    exp!(z)
  else
    Complex(exp!(z.real) * cos!(z.image), exp!(z.real) * sin!(z.image))
  end
end

.exp!Object



449
# File 'lib/complex.rb', line 449

alias exp! exp

.log(z) ⇒ Object

Redefined to handle a Complex argument.



548
549
550
551
552
553
554
555
# File 'lib/complex.rb', line 548

def log(z)
  if Complex.generic?(z) and z >= 0
    log!(z)
  else
    r, theta = z.polar
    Complex(log!(r.abs), theta)
  end
end

.log!Object



450
# File 'lib/complex.rb', line 450

alias log! log

.log10(z) ⇒ Object

Redefined to handle a Complex argument.



558
559
560
561
562
563
564
# File 'lib/complex.rb', line 558

def log10(z)
  if Complex.generic?(z)
    log10!(z)
  else
    log(z)/log!(10)
  end
end

.log10!Object



451
# File 'lib/complex.rb', line 451

alias log10! log10

.sin(z) ⇒ Object

Redefined to handle a Complex argument.



505
506
507
508
509
510
511
512
# File 'lib/complex.rb', line 505

def sin(z)
  if Complex.generic?(z)
    sin!(z)
  else
    Complex(sin!(z.real)*cosh!(z.image),
     cos!(z.real)*sinh!(z.image))
  end
end

.sin!Object



453
# File 'lib/complex.rb', line 453

alias sin! sin

.sinh(z) ⇒ Object



523
524
525
526
527
528
529
# File 'lib/complex.rb', line 523

def sinh(z)
  if Complex.generic?(z)
    sinh!(z)
  else
    Complex( sinh!(z.real)*cos!(z.image), cosh!(z.real)*sin!(z.image) )
  end
end

.sinh!Object



456
# File 'lib/complex.rb', line 456

alias sinh! sinh

.sqrt(z) ⇒ Object

Redefined to handle a Complex argument.



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/complex.rb', line 467

def sqrt(z)
  if Complex.generic?(z)
    if z >= 0
  sqrt!(z)
    else
  Complex(0,sqrt!(-z))
    end
  else
    if z.image < 0
  sqrt(z.conjugate).conjugate
    else
  r = z.abs
  x = z.real
  Complex( sqrt!((r+x)/2), sqrt!((r-x)/2) )
    end
  end
end

.sqrt!Object



448
# File 'lib/complex.rb', line 448

alias sqrt! sqrt

.tan(z) ⇒ Object

Redefined to handle a Complex argument.



515
516
517
518
519
520
521
# File 'lib/complex.rb', line 515

def tan(z)
  if Complex.generic?(z)
    tan!(z)
  else
    sin(z)/cos(z)
  end
end

.tan!Object



454
# File 'lib/complex.rb', line 454

alias tan! tan

.tanh(z) ⇒ Object



539
540
541
542
543
544
545
# File 'lib/complex.rb', line 539

def tanh(z)
  if Complex.generic?(z)
    tanh!(z)
  else
    sinh(z)/cosh(z)
  end
end

.tanh!Object



457
# File 'lib/complex.rb', line 457

alias tanh! tanh