Warum wird einer float-Variablen stop increment bei 16777216 in C#?

float a = 0;
while (true)
{
    a++;
    if (a > 16777216)
        break; //Will never break... a stops at 16777216
}

Kann jemand erklären mir das an, warum ein float-Wert, Stoppt das Inkrementieren bei 16777216 in diesem code?

Edit:

Oder noch einfacher:

float a = 16777217; //a becomes 16777216
stackoverflow.com/questions/3448777/...
stackoverflow.com/questions/6275327/...
Wenn so etwas ist, fangen Sie aus, ich raten Ihnen dringend zu Lesen: Was jeder computer scientist should know about floating-point-Arithmetik. Es wird erläutert, wie Sie sind in hardware implementiert und deckt alle gotcha du wirst irgendwann über den Weg laufen. docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

InformationsquelleAutor Jan | 2012-09-26

Schreibe einen Kommentar