diff --git a/src/polynome.c b/src/polynome.c index 576ae1e..e8490cd 100644 --- a/src/polynome.c +++ b/src/polynome.c @@ -89,10 +89,10 @@ double* get_polynome_factors (polynome_t *poly) factors = malloc ( (poly->order + 1) * sizeof (*factors) ); - ptr = factors + poly->order; + ptr = factors; bal = poly->first; while ( bal ) { - *(ptr--) = bal->factor; + *(ptr++) = bal->factor; bal = bal->next; } return factors; diff --git a/tests/polynomes-cli/builtins.c b/tests/polynomes-cli/builtins.c index e64576a..4c88836 100644 --- a/tests/polynomes-cli/builtins.c +++ b/tests/polynomes-cli/builtins.c @@ -135,7 +135,7 @@ int print (const char* params) factors = get_polynome_factors (poly->polynome); printf("%c(%c) = ",poly->name, sym); while ( fcount ) { - printf("+(%lf) %c^%d ",factors[fcount],sym,--fcount); + printf("+(%lf) %c^%d ",factors[poly->polynome->order - fcount],sym,--fcount); } free (factors); _helper_end_get_params ();