(= e 2.718281828459045235360287471352662497757247093699)
    (= pi 3.14159265358979323846264338327950288419716939937)
    
    (def tocons (z)
         (coerce (coerce z 'string) 'cons))
    
    (def toint (z)
         (coerce (coerce z 'string) 'int))
    
    ;;Realis of complex number z
    (def rez (z)
      (= lz (tocons z))
      (= g (or (pos #\+ lz) (pos #\- lz)))
      (toint (firstn g lz)))
    
    ;;Imaginaris of complex number z
    (def imz (z)
      (= lz (tocons z))
      (= g (or (pos #\+ lz) (pos #\- lz)))
      (toint (if (pos #\i lz) (rem #\i (nthcdr g lz)) 0)))
    
    ;;Modulus of complex number z
    (def modz (z)
         (sqrt (+ (expt (rez z) 2)
         	(expt (imz z) 2))))
    
    ;;These functions return complex numbers.
    ;;They are less efficient when used with reals.
    (def sin (x)
         (/ (- (expt e (* x +i)) (expt e (* x -i))) +2.0i))
    
    (def cos (x)
         (/ (+ (expt e (* x +i)) (expt e (* x -i))) 2.0))
    
    (def tan (x)
         (/ (sin x) (cos x)))
    
    (def cot (x)
         (/ (cos x) (sin x)))
    
    ;;The following functions return real numbers.
    (def rsin (x)
      (imz (expt e (* 0+1.i x))))
    (def rcos (x)
      (rez (expt e (* 0+1.i x))))
    (def rtan (x) 
      (/ (rsin x) (rcos x)))
    (def rcot (x)
      (/ (rcos x) (rsin x)))
 
Enjoy! Any feedback is welcome. You may contact me at wgac@wp.pl |