errors less when the first coefficient is "1"

This commit is contained in:
Krishna Vedala 2020-04-09 09:44:05 -04:00
parent 44f207cd52
commit e485ad5c70
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
1 changed files with 9 additions and 0 deletions

View File

@ -101,6 +101,15 @@ int main(int argc, char **argv)
else if (coeffs[n] != 0)
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 */
if (n < degree - 1)
{