His version at least returns complex answers Wink
Yeah, complex numbers is something I should know more about. Sadly, I don't (yet). Not being able to solve x²+x=0 is just weird behavior by a quadratic solver. For anyone still caring, here is my current code:


Code:
PROGRAM:A
Prompt A,B,C
-.5(B+√(B²-4AC)(2(B≥0)-1
Disp C/Ans
If A:Disp Ans/A


I'd love suggestions on making the program smaller.
A real number and a complex number are two different entities on the calculator, and if it finds that it's about to do a real→complex conversion during its evaluation, it checks the mode first to see whether you're okay with that. "Real" says you're not. If, after simplification of its argument, the square root finds that it must operate on a complex number rather than a real, then no conversion or check is required.

Using that to our advantage, we can add a +0i term to the inside of the square root to force the computation regardless of the mode. In our case, we can even turn √(B²-4AC) into √(B²+4ACi²), which is two bytes more. But, that's fewer than having a+bi at the top of the program, which is one byte for the newline and two bytes for the mode. Plus, you don't have to mess with the user's settings.
And speaking of your routines, Weregoose, are you planning to put them back online someday? Your unitedti.org page was amazing.
Deep Thought wrote:
And speaking of your routines, Weregoose, are you planning to put them back online someday? Your unitedti.org page was amazing.
Definitely agreed! I would be more than happy to host them here in some capacity, of course.
I believe the only time you will get an imaginary number is when the discriminate ends up being negative, otherwise you shouldn't have to worry about it. just set you calc to a+bi before using the program

EDIT: nevermind, looks like you guys got this one figured out Laughing
Yes, the discriminant is indeed how you know if you're going to end up with imaginary roots, since the radical of the discriminant is the only place that an imaginary number could come from in the quadratic formula. Smile A nice thorough quadratic solver will check for imaginary roots and a double root, report either case, and then display one or two roots, as necessary.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement