Ich bin mir nicht sicher, wie man mit Fließkommaausnahmen in C oder C++ umgeht. Laut Wiki gibt es die folgenden Arten von Fließkomma-Ausnahmen:
IEEE 754 specifies five arithmetic errors that are to be recorded in "sticky bits" (by default; note that trapping and other alternatives are optional and, if provided, non-default). * inexact, set if the rounded (and returned) value is different from the mathematically exact result of the operation. * underflow, set if the rounded value is tiny (as specified in IEEE 754) and inexact (or maybe limited to if it has denormalisation loss, as per the 1984 version of IEEE 754), returning a subnormal value (including the zeroes). * overflow, set if the absolute value of the rounded value is too large to be represented (an infinity or maximal finite value is returned, depending on which rounding is used). * divide-by-zero, set if the result is infinite given finite operands (returning an infinity, either + or ). * invalid, set if a real-valued result cannot be returned (like for sqrt(1), or 0/0), returning a quiet NaN.
Wenn eine der oben genannten Ausnahmen auftritt, wird das Programm dann abnormal beendet? Oder führt das Programm diesen Fehler weiter, ohne etwas zu sagen, und erschwert so die Fehlersuche?
Ist ein Compiler wie gcc in der Lage, Warnung für einige offensichtliche Fall geben?
Was kann ich während der Codierung meines Programms tun, um mitzuteilen, wo der Fehler auftritt und um welche Art von Fehler es sich handelt, wenn er auftritt, so dass ich den Fehler in meinem Code leicht finden kann? Bitte geben Sie Lösungen sowohl für C als auch für C++ an.
Vielen Dank und herzliche Grüße!