I think this is the right place to ask this...? Never asked anything before. :P
Soooo...
I'm working on a project that calculates the quadratic formula. Easy peasy, right? No, because I want it to deal with imaginary results as well.
Here's what I've got:
(by the way, the sqrt variable is the returned value of my sqrt function. quad answers is the returned values of the quad formula function, of course. lparen and rparen are parenthesis, but they mess up the block plugin if there.)
quadratic formula a: (a) b: (b) c: (c)
sqrt (((b)*(b))+((-4)*((a)*(c)))) if <(letter (length of (sqrt)) of (sqrt))=[i]> add (join (((-1)*(b))/((2)*(a))) (join [ + lparen] (join (join [i√] (round ((sqrt)*(sqrt)))) (join [rparen / ] ((2)*(a)))))) to [quadratic answers v] add (join (((-1)*(b))/((2)*(a))) (join [ - lparen] (join (join [i√] (round ((sqrt)*(sqrt)))) (join [rparen / ] ((2)*(a)))))) to [quadratic answers v] else add ((((-1)*(b))+(sqrt))/((2)*(a))) to [quadratic answers v] add ((((-1)*(b))-(sqrt))/((2)*(a))) to [quadratic answers v] endsqrt (n)
if <not <([abs v] of (n))=(n)>> set [sqrt v] to (join ([sqrt v] of ([abs v] of (n))) [i]) else set [sqrt v] to ([sqrt v] of (n)) endThe problem I'm having is that if the answer is imaginary, the square root (when squared) is 0. This is because it says the string is 0 because there's a letter in it, i. How can I cast it to get rid of i?
Last edited by veggieman001 (2012-12-08 15:12:50)
Offline
Nevermind, I figured out I could just store the input for the sqrt function as a variable.
Requesting close...
Offline