Steve Summit / Teil9
 
StartSeite | SteveSummit/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern

Top Prev Next

Computer Representation of Numbers

Zahlendarstellung im Rechner

[53] Most computers represent integers as binary numbers (see the "math refresher" handout) with a certain number of bits. A computer with 16-bit integers can represent integers from 0 to 65,535 (that is, from 0 to 216-1), or if it chooses to make half of them negative, from -32,767 to 32,767. (We won't get into the details of how computers handle negative numbers right now.) A 32-bit integer can represent values from 0 to 4,294,967,295, or +-2,147,483,647.
Meist werden ganze Zahlen im Rechner binär mit einer gewissen Anzahl Bits dargestellt. Mit 16-Bit-Zahlen können Werte von 0 bis 65535 (also 0 bis 2^16-1) dargestellt werden; oder, falls die Hälfte des Bereichs für negative Werte vorgesehen ist, von -32767 bis 32767. (Die Einzelheiten der Darstellung negativer Zahlen übergehen wir vorerst.) Eine 32-Bit-Zahl kann Werte von 0 bis 4.294.967.295 annehmen, oder von -2.147.483.647 bis +2.147.483.647.

[54] Most of today's computers represent real (i.e. fractional) numbers using exponential notation. (Again, see "math refresher" handout. Actually, deep down inside, computers usually use powers of 2 instead of powers of 10, but the difference isn't important to us right now.) The advantage of using exponential notation for real numbers is that it lets you trade off the range and precision of values in a useful way. Since there's an infinitely large number of real numbers (and in three directions: very large, very small, and very negative), it will never be possible to represent all of them (without using potentially infinite amounts of space).
Die meisten heutigen Rechner stellen Fliesskommazahlen (gebrochene Zahlen) mit Hilfe der Exponentialnotation dar. Der Vorteil dieser Darstellung ist, dass man den Wertebereich und die Anzahl gültiger Stellen beide sinnvoll ausnutzen kann. Es ist jedoch nicht möglich, alle gebrochenen Werte als Fliesskommazahlen abzubilden. Da es pro Zahl nur eine begrenzte Menge an Speicherplatz gibt, sind sowohl der Genauigkeit als auch dem Wertebereich Grenzen gesetzt.

[55] Suppose you decide to give yourself six decimal digits' worth of storage (that is, you decide to devote an amount of memory capable of holding six digits) for each value. If you put three digits to the left and three to the right of the decimal point, you could represent numbers from 999.999 to -999.999, and as small as 0.001. (Furthermore, you'd have a resulution of 0.001 everywhere: you could represent 0.001 and 0.002, as well as 999.998 and 999.999.) This would be a workable scheme, although 0.001 isn't a very small number and 999.999 isn't a very big one.
Angenommen, man verwendet 6 Dezimalziffern für eine Fliesskommazahl, und teilt diese auf in 3 Vorkommaziffern und 3 Nachkommaziffern, dann kann man Werte von -999,999 bis 999,999 damit speichern; die kleinste positive Zahl wäre 0,001. Auch die Auflösung wäre 0,001, man könnte also z. B. 0,001 und 0,002 darstellen, ebenso wie 999,998 oder 999,999. Dies wäre eine mögliche Abbildung, wenn auch eine unpraktische, da sowohl Wertebereich als auch Auflösung nicht besonders beeindruckend sind.

[56] If, on the other hand, you used exponential notation, with four digits for the base number and two digits for the exponent, you could represent numbers from 9.999 x 1099 to -9.999 x 1099, and as small as 1 x 10-99 (or, if you cheat, 0.001 x 10-99). You can now represent both much larger numbers and much smaller; the tradeoff is that the absolute resolution is no longer constant, and gets smaller as the absolute value of the numbers gets larger. The number 123.456 can only be represented as 123.4, and the number 123,456 can only be represented as 123,400. You can't represent 999.999 any more; you have to settle for 999.9 (9.999 x 102) or 1000 (1.000 x 103). You can't distinguish between 999.998 and 999.999 any more.
Wenn man jedoch andererseits eine exponentielle Darstellung verwendet, die 4 Ziffern für die Mantisse und 2 Ziffern für den Exponenten nutzt, dann kann man Werte zwischen 9,999*10^99 und -9,999*10^99 abbilden, und die kleinste positive Zahl ist 1*10^-99. (Mit nichtnormalisierter Darstellung sogar: 0,001*10^-99.) Dies erlaubt die Verwendung betragsmäßig viel größerer und viel kleinerer Werte; dem entgegen steht, dass die Auflösung nicht mehr konstant ist, sondern schlechter wird, je grösser die Zahlen werden. Beispielsweise muss 123,456 als 123,4 gespeichert werden, und 123.456 als 123.400. 999,999 kann überhaupt nicht mehr dargestellt werden, man muss sich zwischen 999,9 (in Wirklichkeit 9,999*10^2) oder 1000 (in Wirklichkeit 1,000*10^3) entscheiden. 999,998 und 999,999 sind nicht mehr unterscheidbar.

[57] Since superscripts are difficult to type, computer programming languages usually use a slightly different notation. For example, the number 1.234 x 105 might be indicated by 1.234e5, where the letter e replaces the "times ten to the" part.
Zur Minimierung des Schreibaufwands wird normalerweise eine andere Schreibweise in Programmquellen verwendet. Die Zahl 1,234*10^5 wäre dann als 1.234e5 zu schreiben; das "e" darin bedeutet "mal 10 hoch". Auch ist das Dezimalkomma durch den angloamerikanischen Dezimalpunkt zu ersetzen, und die Trennpunkte der Tausenderstellen entfallen.

[58] You will often hear real, exponential numbers numbers referred to on computers as "floating point numbers" or simply "floats," and you will also hear the term "double" which is short for "double-precision floating point number." Some computers also use "fixed point" real numbers, (which work along the lines of our "three to the left, three to the right" example of a few paragraphs back), but those are comparatively rare and we won't need to discuss them.
Gebrochene Zahlen in Exponentialschreibweise werden im Zusammenhang mit Rechnern oft als "Fließkommazahlen" oder "floats" bezeichnet. Man verwendet auch den Begriff "double" zur Benennung von Fließkommazahlen mit doppelter Genauigkeit (d.h. die Mantisse hat die doppelte Länge). Letztlich ist es auch möglich, "echte Fliesskommazahlen" zu verwenden, das sind diejenigen die nicht in Exponentialdarstellung gespeichert werden, wie im ersten Beispiel mit den 3 Stellen vor dem und nach dem Komma; diese werden hier jedoch nicht weiter beschrieben.

[59] It's important to remember that the precision of floating-point numbers is usually limited, and this can lead to surprising results. The result of a division like 1/3 cannot be represented exactly (it's an infinitely repeating fraction, 0.333333...), so the computation (1 / 3) x 3 tends to yield a result like 0.999999... instead of 1.0. Furthermore, in base 2, the fraction 1/10, or 0.1 in decimal, is also an infinitely repeating fraction, and cannot be represented exactly, either, so (1 / 10) x 10 may also yield 0.999999.... For these reasons and others, floating-point calculations are rarely exact. When working with computer floating point, you have to be careful not to compare two numbers for exact equality, and you have to ensure that "round off error" doesn't accumulate until it seriously degrades the results of your calculations.
Wichtig ist, stets zu bedenken, dass die Auflösung von Fließkommawerten begrenzt ist, was zu Rundungsfehlern führt, die oft unerwartete Ergebnisse hervorrufen. Als Beispiel: 1/3 kann nicht exakt dargestellt werden, da der periodische Bruch 0,33333... nicht endet. Folglich liefert die Berechnung von (1/3)*3 nicht 1 sondern 0,999999999... Ein weiteres Beispiel: 1/10 kann in der Binärdarstellung nicht exakt dargestellt werden sondern ist darin ebenfalls ein periodischer Bruch; folglich ist auch (1/10)*10 oft nicht exakt 1 sondern eher 0,999999999... Aus all diesen Gründen liefern Berechnungen mit Fliesskommazahlen normalerweise keine exakten Ergebnisse sondern Annäherungen. Insbesondere sollten Fließkommazahlen nicht auf Gleichheit getestet werden; und der Programmierer muss stets darauf achten, dass Rundungsfehler sich nicht derart aufschaukeln, dass das Endergebnis völlig unbrauchbar wird.


Top Prev Next
StartSeite | SteveSummit/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern
Text dieser Seite ändern (zuletzt geändert: 13. Mai 2002 21:10 (diff))
Suchbegriff: gesucht wird
im Titel
im Text