Precision issues in C language

      No matter how accurate the instrument is, there will be errors, including computers, so the error value should be taken into account when writing programs. Usually, a precision EPS is specified at the beginning of the program. If the calculation result is within the positive and negative range of this error value, it is correct. If it exceeds this range, it is wrong. The following is an example of a program that needs to consider the error: find the solution of the quadratic equation ax^2+bx+c=0 in one variable (the case of equal real roots and unequal real roots).

(1) a=0, then x1=x2=(-c)/b;

(2) a is not equal to 0: b^2-4ac>0; there are two unequal real roots

                          b^2-4ac<0; no real root

                          b^-4ac=0; there are two equal real roots

Because the error is considered, it is necessary to replace 0 with the specified EPS, as follows:


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325337310&siteId=291194637