No estoy seguro de cómo lidiar con excepciones de coma flotante en C o C++. De wiki, existen los siguientes tipos de excepciones de punto flotante:Tratando con excepciones de punto flotante
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.
es que cuando cualquier tipo de excepciones anteriores sucede, el programa se cierra de forma imprevista? ¿O el programa llevará este error sin mencionar nada y por lo tanto hará que el error sea difícil de depurar?
¿Es capaz un compilador como gcc de dar una advertencia para algún caso obvio?
Qué puedo hacer durante mi programa de codificación para notificar cuando ocurre el error y qué tipos se cuando sucede, de modo que pueda localizar fácilmente el error en mi código? Proporcione soluciones en los casos C y C++.
¡Gracias y saludos!
es probable que las respuestas sean específicas de un sistema operativo. ¿Tienes uno en mente? –
Tanto Linux como Windows, aunque ahora estoy usando Linux con más frecuencia. – Tim
No veo cómo la semántica de coma flotante definida por ISO/IEEE dependerá del sistema operativo. – Jeff