Re: C2124 is most disrespectful of IEEE floating point arithmetic



Tom Widmer [VC++ MVP] wrote:
Dr Pizza wrote:
Actually, IEC 559 makes no such guarantee. 1.0/0.0 produces a
division by zero exception, which may cause a trap depending on
whether a trap handler is set up (which it apparently is in the
compiler!).
Er, if traps are disabled (which IEC 559 allows) then IEC 559
explicitly guarantees the result. If the compiler has traps enabled
thereby preventing it from compiling programs whose semantics are
well-defined and legal the the compiler is at fault IMO.

In addition, IEC 559 does not define how source code maps
onto floating point operations, and nor does the C++ standard for
that matter, so that's really up to the compiler (and indeed, some
compilers use extended precision registers for intermediate
operations, etc.).
The C++ compiler shouldn't trap perfectly sound expressions.

Regarding the case where the double isn't a global (and therefore the
initializer isn't a constant-expression), I agree that MS would be
better to define their undefined behaviour as returning +inf, but at
least the error forces you to be explicit, and use infinity() when
you mean it.
1.0 / 0.0 is a perfectly good IEC 559 alternative.


--

.



Relevant Pages

  • Re: why is lisp fast?
    ... Lookup '+' from the environment, ... Imagine you'd have a C compiler able to generate code from such a program: ... (defun fact (n) ...
    (comp.lang.lisp)
  • Trap Representations - c99 [again]
    ... As far as I understand it, a trap representation means something like - ... firstly I'd like to know whether my interpretations of the standard are ... It seems to me that, for example, a char cannot possibly contain an implict ... Building upon that, every C compiler I've ...
    (comp.lang.c)
  • Re: Trap Representations - c99 [again]
    ... As far as I understand it, a trap representation means something like - ... It seems to me that, for example, a char cannot possibly contain an implict ... Building upon that, every C compiler I've ...
    (comp.lang.c)
  • Re: A salutary tale about alignment and undefined behaviour
    ... On some machines the assignment to eh might cause the pointer ... or even cause a trap because it's an invalid ... Optimisation can cause a lot of problems. ... which compiler was it which bit you? ...
    (comp.lang.c)
  • Re: Can generics really produce strongly typed collections?
    ... and if it happens that an item in this collection, which foreach ... and an explicit cast ) overrides the compiler's normal type rules. ... But, the compiler uses only the implicitly implemented interface, assuming one exists. ... If you implement IEnumerator implicitly and IEnumeratorexplicitly, then "foreach" will find the non-generic version in a "foreach" that tries to use "int", and _it will use it_. ...
    (microsoft.public.dotnet.languages.csharp)

Loading