mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
errors less when the first coefficient is "1"
This commit is contained in:
parent
44f207cd52
commit
e485ad5c70
@ -101,6 +101,15 @@ int main(int argc, char **argv)
|
|||||||
else if (coeffs[n] != 0)
|
else if (coeffs[n] != 0)
|
||||||
printf("(%g) x^%d = 0\n", coeffs[n], degree - n - 1);
|
printf("(%g) x^%d = 0\n", coeffs[n], degree - n - 1);
|
||||||
|
|
||||||
|
double tmp;
|
||||||
|
if (n > 0)
|
||||||
|
coeffs[n] /= tmp; /* numerical errors less when the first coefficient is "1" */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp = coeffs[0];
|
||||||
|
coeffs[0] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* initialize root approximations with random values */
|
/* initialize root approximations with random values */
|
||||||
if (n < degree - 1)
|
if (n < degree - 1)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user