I'm new to Snap! and I have a question. When working with my project here, I wanted to convert a complex number to exponential form. However, when calculating the argument and magnitude, it would always return a not very nice decimal, which is a hindrance in exponential form. For example, if I had something as so:
Re(z) = sqrt(3)/2
Im(z) = 1/2
= 5 * e^i(0.535374144)pi
I would want to have
= 5 * e^i(pi/6)
Is this possible, without having the computer make an immense list of decimals that can be converted in to nice fractions?
Once you've computed that sqrt(3), you're not going to get an exact answer to any later computation that depends on it. There are a couple of things you can do:
Easy but not quite what you want: You can round the answer to some number of decimal places. Let's say you want three digits after the decimal point; you can say
Hard but perfect: Start by loading the bignums library. Invent a representation for exact square roots, e.g.,
and build your own SQUARE function that recognizes those things and returns the exact result. Also you'll need your own arithmetic operators in general so that, for example,