'
'Option Explicit no longer needed as it is default for FB0.17f and later.. '+------------------------------------------------------------------------------------------+ '| Header: Evaluation of parameters | '| DisplayCheck:|Il1 are Alt-0124, Big i, small L, One ᎙=ܱ | Const Author="QuadEqus.Bas 2009 by ytwinky, MD"' | '| (ShortCut: none) | '| THIS IS THE ONLY GOTO IN THE WHOLE PROGRAM.. | '| Purpose: Solve quadratic equations(general form) | '+------------------------------------------------------------------------------------------+ Type Real As Double Type QuaEquRec As Real x1, x2 As Integer SqrErr End Type Declare Function qegf(a As Real=1, b As Real, c As Real=0) As QuaEquRec Dim x As QuaEquRec Print Author Print "1.:Solve the equation 2x^2+4x-48=0" x=qegf(2, 4, -48) Print "x1=" &x.x1 &" x2=" &x.x2 &" SqrErr=" &x.SqrErr Print "Now check 2*" &x.x1 &"^2+4*" &x.x1 &"-48=0, Result:" &(2*x.x1^2+4*x.x1-48) Print "And also 2*" &x.x2 &"^2+4*" &x.x2 &"-48=0, Result:" &(2*x.x2^2+4*x.x2-48) Print "2.:Solve the equation x^2+2x-24=0" x=qegf(, 2, -24) Print "x1=" &x.x1 &" x2=" &x.x2 &" SqrErr=" &x.SqrErr &!"\n" _ &"Now check " &x.x1 &"^2+2*" &x.x1 &"-24=0, Result:" &(x.x1^2+2*x.x1-24) _ &!"\nAnd also " &x.x2 &"^2+2*" &x.x2 &"-24=0, Result:" &(x.x2^2+2*x.x2-24) _ &!"\nExplanation of SqrErr:\nSqrErr=0 ==> no Error\nSqrErr=27 ==> a=0, but a must be<>0" _ &!"\nSqrErr=-1 ==> radicand<0, but radicand must not be<0" GetKey End Function qegf(a As Real=1, b As Real, c As Real=0) As QuaEquRec Dim Result As QuaEquRec Dim As Real p, q, d If a=0 Then Result.SqrErr=27 Else p=b/a q=c/a d=p*p/4-q If d<0 Then Result.SqrErr=-1 Else Result.x1=-p*0.5+Sqr(d) Result.x2=-p*0.5-Sqr(d) Result.SqrErr=0 End If End If Return Result End Function