home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Clean 1.2.4 / IO Examples / Mandelbrot / Complex.icl < prev    next >
Encoding:
Modula Implementation  |  1996-12-17  |  923 b   |  45 lines  |  [TEXT/3PRM]

  1. implementation module Complex
  2.  
  3. import StdReal
  4.     
  5. ::    ComplexNum :== (!Real,!Real)
  6.     
  7. AddC :: !ComplexNum !ComplexNum -> ComplexNum
  8. AddC (re_a,im_a) (re_b,im_b) = (re_a+re_b,im_a+im_b)
  9.  
  10. SubC :: !ComplexNum !ComplexNum -> ComplexNum
  11. SubC (re_a,im_a) (re_b,im_b) = (re_a-re_b,im_a-im_b)
  12.  
  13. MulC :: !ComplexNum !ComplexNum -> ComplexNum
  14. MulC (re_a,im_a) (re_b,im_b) = (re_a*re_b - im_a*im_b,re_a*im_b + im_a*re_b)
  15.  
  16. FakeAbsC :: !ComplexNum -> Real
  17. FakeAbsC (re,im) = re*re + im*im
  18.  
  19. //    More complex functions
  20. SinC :: !ComplexNum -> ComplexNum
  21. SinC (re,im)
  22. =    let!
  23.         a     = cos re * (emim-eim)
  24.         b     = sin re * (emim+eim)
  25.         emim = 1.0 / eim
  26.         eim     = exp im
  27.     in
  28.         (0.5*b, (-0.5)*a)
  29.  
  30. CosC :: !ComplexNum -> ComplexNum
  31. CosC (re,im)
  32. =    let!
  33.         a     = cos re * (emim+eim)
  34.         b     = sin re * (emim-eim)
  35.         emim = 1.0 / eim
  36.         eim     = exp im
  37.     in
  38.         (0.5*a,0.5*b)
  39.  
  40. ExpC :: !ComplexNum -> ComplexNum
  41. ExpC (re,im)
  42. =    (a*cos im,a*sin im)
  43. where
  44.     a    = exp re
  45.