Module: Math

Includes:
Hornetseye::Methods
Defined in:
lib/multiarray/complex.rb,
lib/multiarray/methods.rb,
lib/multiarray/rgb.rb

Overview

The Math module is extended with a few methods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hornetseye::Methods

define_binary_method, define_unary_method, included

Class Method Details

.acosObject

.acos_without_internalcomplexObject

.acoshObject

.acosh_without_internalcomplexObject

.asinObject

.asin_without_internalcomplexObject

.asinhObject

.asinh_without_internalcomplexObject

.atanObject

.atan2Object

.atan2_without_internalcomplexObject

.atan_without_internalcomplexObject

.atanhObject

.atanh_without_internalcomplexObject

.cosObject

.cos_without_internalcomplexObject

.coshObject

.cosh_without_internalcomplexObject

.expObject

.exp_without_internalcomplexObject

.logObject

.log10Object

.log10_without_internalcomplexObject

.log_without_internalcomplexObject

.log_without_rgbObject

.sinObject

.sin_without_internalcomplexObject

.sinhObject

.sinh_without_internalcomplexObject

.sqrtObject

.sqrt_without_internalcomplexObject

.sqrt_without_rgbObject

.tanObject

.tan_without_internalcomplexObject

.tanhObject

.tanh_without_internalcomplexObject

Instance Method Details

#acos_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Arcus cosinus for internal complex numbers

Parameters:

Returns:



556
557
558
559
560
561
562
# File 'lib/multiarray/complex.rb', line 556

def acos_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    -1.0.im * log( z + 1.0.im * sqrt( 1.0 - z * z ) )
  else
    acos_without_internalcomplex z
  end
end

#acosh_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Arcus cosinus hyperbolicus for internal complex numbers

Parameters:

Returns:



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

def acosh_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    log( z + sqrt( z * z - 1.0 ) )
  else
    acosh_without_internalcomplex z
  end
end

#asin_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Arcus sinus for internal complex numbers

Parameters:

Returns:



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

def asin_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    -1.0.im * log( 1.0.im * z + sqrt( 1.0 - z * z ) )
  else
    asin_without_internalcomplex z
  end
end

#asinh_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Arcus sinus hyperbolicus for internal complex numbers

Parameters:

Returns:



632
633
634
635
636
637
638
# File 'lib/multiarray/complex.rb', line 632

def asinh_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    log( z + sqrt( 1.0 + z * z ) )
  else
    asinh_without_internalcomplex z
  end
end

#atan2_with_internalcomplex(y, x) ⇒ Object, Hornetseye::InternalComplex

Arcus tangens of two internal complex numbers

Parameters:

Returns:



670
671
672
673
674
675
676
# File 'lib/multiarray/complex.rb', line 670

def atan2_with_internalcomplex( y, x )
  if [ x, y ].any? { |v| v.is_a? Hornetseye::InternalComplex }
    -1.0.im * log( ( x + 1.0.im * y ) / sqrt( x * x + y * y ) )
  else
    atan2_without_internalcomplex y, x
  end
end

#atan_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Arcus tangens for internal complex numbers

Parameters:

Returns:



594
595
596
597
598
599
600
# File 'lib/multiarray/complex.rb', line 594

def atan_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    1.0.im * log( ( 1.0.im + z ) / ( 1.0.im - z ) ) / 2.0
  else
    atan_without_internalcomplex z
  end
end

#atanh_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Arcus tangens hyperbolicus for internal complex numbers

Parameters:

Returns:



651
652
653
654
655
656
657
# File 'lib/multiarray/complex.rb', line 651

def atanh_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    log( ( 1.0 + z ) / ( 1.0 - z ) ) / 2.0
  else
    atanh_without_internalcomplex z
  end
end

#cos_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Cosinus for internal complex numbers

Parameters:

Returns:



395
396
397
398
399
400
401
402
403
# File 'lib/multiarray/complex.rb', line 395

def cos_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    real = cos( z.real ) * cosh( z.imag )
    imag = -sin( z.real ) * sinh( z.imag )
    Hornetseye::InternalComplex.new real, imag
  else
    cos_without_internalcomplex z
  end
end

#cosh_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Cosinus hyperbolicus for internal complex numbers

Parameters:

Returns:



456
457
458
459
460
461
462
463
464
# File 'lib/multiarray/complex.rb', line 456

def cosh_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    real = cosh( z.real ) * cos( z.imag )
    imag = sinh( z.real ) * sin( z.imag )
    Hornetseye::InternalComplex.new real, imag
  else
    cosh_without_internalcomplex z
  end
end

#exp_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Exponent for internal complex numbers

Parameters:

Returns:



374
375
376
377
378
379
380
381
382
# File 'lib/multiarray/complex.rb', line 374

def exp_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    real = exp( z.real ) * cos( z.imag )
    imag = exp( z.real ) * sin( z.imag )
    Hornetseye::InternalComplex.new real, imag
  else
    exp_without_internalcomplex z
  end
end

#log10_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Base-10 logarithm for internal complex numbers

Parameters:

Returns:



537
538
539
540
541
542
543
# File 'lib/multiarray/complex.rb', line 537

def log10_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    log(z) / log( 10 )
  else
    log10_without_internalcomplex z
  end
end

#log_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Logarithm for internal complex numbers

Parameters:

Returns:



517
518
519
520
521
522
523
524
# File 'lib/multiarray/complex.rb', line 517

def log_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    r, theta = z.polar
    Hornetseye::InternalComplex.new log( r.abs ), theta
  else
    log_without_internalcomplex z
  end
end

#log_with_rgb(c) ⇒ Object



952
953
954
955
956
957
958
# File 'lib/multiarray/rgb.rb', line 952

def log_with_rgb(c)
  if c.is_a? Hornetseye::RGB
    Hornetseye::RGB.new log( c.r ), log( c.g ), log( c.b )
  else
    log_without_rgb c
  end
end

#sin_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Sinus for internal complex numbers

Parameters:

Returns:



416
417
418
419
420
421
422
423
424
# File 'lib/multiarray/complex.rb', line 416

def sin_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    real = sin( z.real ) * cosh( z.imag )
    imag = cos( z.real ) * sinh( z.imag )
    Hornetseye::InternalComplex.new real, imag
  else
    sin_without_internalcomplex z
  end
end

#sinh_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Sinus hyperbolicus for internal complex numbers

Parameters:

Returns:



477
478
479
480
481
482
483
484
485
# File 'lib/multiarray/complex.rb', line 477

def sinh_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    real = sinh( z.real ) * cos( z.imag )
    imag = cosh( z.real ) * sin( z.imag )
    Hornetseye::InternalComplex.new real, imag
  else
    sinh_without_internalcomplex z
  end
end

#sqrt_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Square root for internal complex numbers

Parameters:

Returns:



352
353
354
355
356
357
358
359
360
361
# File 'lib/multiarray/complex.rb', line 352

def sqrt_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    real = sqrt( ( z.abs + z.real ) / 2 )
    imag = ( z.imag < 0 ).conditional -sqrt( ( z.abs - z.real ) / 2 ),
                                      sqrt( ( z.abs - z.real ) / 2 )
    Hornetseye::InternalComplex.new real, imag
  else
    sqrt_without_internalcomplex z
  end
end

#sqrt_with_rgb(c) ⇒ Object



940
941
942
943
944
945
946
# File 'lib/multiarray/rgb.rb', line 940

def sqrt_with_rgb(c)
  if c.is_a? Hornetseye::RGB
    Hornetseye::RGB.new sqrt( c.r ), sqrt( c.g ), sqrt( c.b )
  else
    sqrt_without_rgb c
  end
end

#tan_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Tangens for internal complex numbers

Parameters:

Returns:



437
438
439
440
441
442
443
# File 'lib/multiarray/complex.rb', line 437

def tan_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    sin(z) / cos(z)
  else
    tan_without_internalcomplex z
  end
end

#tanh_with_internalcomplex(z) ⇒ Object, Hornetseye::InternalComplex

Tangens hyperbolicus for internal complex numbers

Parameters:

Returns:



498
499
500
501
502
503
504
# File 'lib/multiarray/complex.rb', line 498

def tanh_with_internalcomplex(z)
  if z.is_a? Hornetseye::InternalComplex
    sinh(z) / cosh(z)
  else
    tanh_without_internalcomplex z
  end
end