Non sono sicuro di come gestire le eccezioni in virgola mobile in C o C++. Da wiki, ci sono i seguenti tipi di floating point eccezioni:Gestione delle eccezioni a virgola mobile
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.
è che quando qualsiasi tipo di cui sopra eccezioni accade, il programma si chiude in modo anomalo? O il programma trasporterà questo errore senza menzionare nulla e quindi rendere l'errore difficile da eseguire il debug?
È un compilatore come gcc in grado di dare un avviso per qualche caso ovvio?
Cosa posso fare durante la codifica del mio programma per notificare dove si verifica l'errore e che tipo è quando accade, in modo che possa individuare facilmente l'errore nel mio codice? Si prega di fornire soluzioni in entrambi i casi C e C++.
Grazie e saluti!
risposte saranno probabilmente specifiche per un sistema operativo. Ne hai uno in mente? –
Sia linux che windows, anche se ora sto usando Linux più spesso. – Tim
Non vedo come la semantica in virgola mobile definita da ISO/IEEE sarà dipendente dal sistema operativo. – Jeff