Arc Forumnew | comments | leaders | submitlogin
2 points by conanite 5670 days ago | link | parent

Awesome work. Watch out for the numerous number formats scheme allows -

  1.3e-32-4.3e+56i
  3/8-4.3e+56i
I can attest that it's hell to parse these numbers - and imz returns 56 in each of these cases. You might need to use real-part and imag-part from scheme if you don't want to write a complex number parser in arc :)


1 point by wgac 5662 days ago | link

I found some errors in the recent post. Here is the (I hope so) final version or rez and imz. Enjoy :)

    ;;Realis of complex number z
    (def rez (z)
         (with (lz (tocons z) i 0 j 0)
         (until (or (is i (len lz))
                    (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 (or (is i (len lz))
         	    	(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))))

-----

1 point by wgac 5665 days ago | link

Thanks for the feedback, conanite :) I think I know how to cope with that problem. I'll post my results as soon as I have some spare time. I'm also planning to successively add more elaborate mathematical functions. Maybe some numerical integration or solving differential equations.

-----