identification division.
program-id. sqrt-real.
* aus Wirth, systematisches Programmieren p. 61
author. "JD".
date-written. 11.9.2005.
date-compiled.
data division.
working-storage section.
77 a pic 9(4)V9(4).
77 c pic 9(4)V9(4).
77 eps pic 9(4)V9(4) value 0.001.
linkage section.
77 x pic 9(4)V9(4).
77 r pic 9(4)V9(4).
procedure division using x r.
* computes x * (1-) <= a**2 < x
move a to x
compute c = 1 - x.
perform until c <= eps
* invariant a**2 = x * (1 - c), c >= 0
compute a = a*(1+0.5*c)
compute c = c*c*(0.75+0.25*c)
end-perform.
move x to r.
end-program sqrt-real.
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
|
Haftungshinweis
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.
|