Einzelnen Beitrag anzeigen

gammatester

Registriert seit: 6. Dez 2005
999 Beiträge
 
#2

AW: Small piece from JavaScript to Delphi won't work

  Alt 16. Jul 2018, 20:18
Your translation of do {..} while is wrong. Your stopping criterion should be as given below
Delphi-Quellcode:
 repeat
    a := Floor(b);
    aux := h1;
    h1 := a*h1+h2;
    h2 := aux;
    aux := k1;
    k1 := a*k1+k2;
    k2 := aux;
    if a=b then break;
    b := 1/(b-a);
  until (Abs(x - h1 / k1) <= x * tolerance);
Note the safe-guard against division by zero. Don't know why JS can divide by zero - or is it quietly ignored?

With these changes you get 9.5 = 19/2.
  Mit Zitat antworten Zitat