MC68HC11 Quadratic Equation

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC68HC11 Quadratic Equation

1,022 Views
junkbonkin
Contributor I
I Am trying to write a small program to solve the quadratic equation and i was wondering if anyone could help the numbers are A=1 B=4 and C=5 thanks for your help in advance and also does anyone know of a good free ware 68hc11 emulator i had THRsim11 but the trial is almost over thank you in advance
Labels (1)
0 Kudos
2 Replies

303 Views
junkbonkin
Contributor I
unfortunately i am using one that can only take mnemonic code or opcode but thank you for the help
0 Kudos

303 Views
bigmac
Specialist III
Hello,
 
Assuming you have resources to accommodate floating point mathematics, the following untested function should give the solutions to the quadradic equation, for both real and complex cases.
 
#include "math.h"
 
/* Global variables for result */
double r1, i1;  // First solution
double r2, i2;  // Second solution
 
void quadratic (double a, double b, double c)
{
  double t;
 
  b = b/a;
  c = c/a;
  t = b*b/2 - c;
  if (t < 0)  {
     /* Complex solution */
     r1 = -0.5*b;
     i1 = sqrt(-t);
     r2 = r1;
     i2 = -i1;
  }
  else {
     /* Real solution */
     t = sqrt(t);
     r1 = -0.5*b + t;
     i1 = 0;
     r2 = -0.5*b - t;
     i2 = 0;
  }
}
 
For the coefficients given in your post, the solution will be complex -
-2+j1, -2-j1
 
Regards,
Mac
 
0 Kudos