Arc Forumnew | comments | leaders | submitlogin
2 points by wgac 5694 days ago | link | parent

Ok. So I've looked at the rez and imz and found the solution to the problem with scientific notation. Here are my results:

    ;;Realis of complex number z
    (def rez (z)
      (with (lz (tocons z) i 0 j 0)
      (until (and (isnt (lz j) #\e) (or (is (lz i) #\+) (is (lz i) #\-))) 
           	  (if (is i 0) (++ i) (do (++ i) (++ j))))
      (toint (firstn i lz))))

    ;;Imaginaris of complex number z
    (def imz (z)
      (with (lz (tocons z) i 0 j 0)
      (until (and (isnt (lz j) #\e) (or (is (lz i) #\+) (is (lz i) #\-))) 
           	  (if (is i 0) (++ i) (do (++ i) (++ j))))    
      (toint (if (pos #\i lz) (rem #\i (nthcdr i lz)) 0))))
I've also written zbar which returns complex conjugate of a number:

    ;;Complex conjugate of number z.
    (def zbar (z)
         (toint (join (tocons (rez z)) 
         	      (if (> (imz z) 0) '(#\-) '(#\+)) 
		      (tocons (abs (imz z))) 
		      '(#\i))))
And once more thank you, conanite.