Re: C2124 is most disrespectful of IEEE floating point arithmetic



This is a compile-time constant expression, and is evaluated on compilation
time.

"Dr Pizza" <DrPizza@xxxxxxxxxxxxxxxxx> wrote in message
news:xn0eqhw1a4lwx05000@xxxxxxxxxxxxxxxxxxxxxxx
Since VC++ purports to follow IEC 559, and IEC 559 defines the division
of a non-zero by a zero to be a signed infinity, isn't it rather silly
that:

float inf(1.0f / 0.0f);

should result in a compile-time error, C2124? An error may be
appropriate for integer arithmetic (as it'll generate a runtime SEH
exception), but for floating point arithmetic it's surely incorrect
behaviour?

What gives? Am I being unreasonable in my expectations? It's
certainly rather nicer to type the above than have to spew:

float inf(std::numeric_limits<float>::infinity());

--



.



Relevant Pages

  • Re: C2124 is most disrespectful of IEEE floating point arithmetic
    ... Treatment of division by zero, forming a remainder using a zero ... For a compile-time expression, ... So depending on our handling of FP exceptions we should see one of two ... we have a compile-time error. ...
    (microsoft.public.vc.language)
  • Re: C2124 is most disrespectful of IEEE floating point arithmetic
    ... Division by zero is undefined, so the compiler can do whatever it ... For a compile-time expression, ... then the division by zero exception shall be signaled. ... a signed infinity; ...
    (microsoft.public.vc.language)
  • Re: C2124 is most disrespectful of IEEE floating point arithmetic
    ... of a non-zero by a zero to be a signed infinity, ... float inf; ... Division by zero is undefined, so the compiler can do whatever it wants. ... For a compile-time expression, emitting an error is highly appropriate. ...
    (microsoft.public.vc.language)
  • Re: $@ Evaluation Error Oddity
    ... Optimization steps can make for twisty logic. ... single number during the compile phase in an optimizing step called ... The difference in compile-time behavior is this: ... The behavior is the same in both cases - a compile-time error. ...
    (comp.lang.perl.misc)
  • Re: Having a little problem with reflection
    ... The class loader simply loads the class called classname. ... source of your compile-time error), then this will cause an exception. ...
    (comp.lang.java.programmer)

Loading