Re: C2124 is most disrespectful of IEEE floating point arithmetic
- From: "Dr Pizza" <DrPizza@xxxxxxxxxxxxxxxxx>
- Date: Mon, 28 Aug 2006 03:45:24 -0700
John Carson wrote:
"Dr Pizza" <DrPizza@xxxxxxxxxxxxxxxxx> wrote in message
news:xn0eqhw1a4lwx05000@xxxxxxxxxxxxxxxxxxxx
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());
For what it is worth, this compiles:
float zero = 0.0f;
float f(1.0f/zero);
as does
const float zero = 0.0f;
float f(1.0f/zero);
It is apparently only a literal zero that gives a problem.
Weird. I had expected that the compiler would propagate the constant
zero and emit the same error, but looking at the generated assembly it
doesn't; it performs a runtime division.
--
.
- Follow-Ups:
- Re: C2124 is most disrespectful of IEEE floating point arithmetic
- From: Abdo Haji-Ali
- Re: C2124 is most disrespectful of IEEE floating point arithmetic
- References:
- C2124 is most disrespectful of IEEE floating point arithmetic
- From: Dr Pizza
- Re: C2124 is most disrespectful of IEEE floating point arithmetic
- From: John Carson
- C2124 is most disrespectful of IEEE floating point arithmetic
- Prev by Date: Re: C2124 is most disrespectful of IEEE floating point arithmetic
- Next by Date: Re: ISO image
- Previous by thread: Re: C2124 is most disrespectful of IEEE floating point arithmetic
- Next by thread: Re: C2124 is most disrespectful of IEEE floating point arithmetic
- Index(es):
Relevant Pages
|