# a question about constant fold for fdiv

Hello, I have a question about the constant folding for fdiv instructions. For the instruction "fdiv double 0.0, 0.0", the folded result is inf. I think this should be nan. Can anyone tell me why it is not nan?
Thanks.

Leo

Hello, I have a question about the constant folding for fdiv instructions.
For the instruction "fdiv double 0.0, 0.0", the folded result is inf. I
think this should be nan. Can anyone tell me why it is not nan?

I think the specification says that it is "undefined" so any value will
do. inf is just as undefined as nan.

Reid.

I seem to recall that gcc's interpretation of undefined in this
situation is also inf.

Andrew

Reid Spencer wrote:

``````
``````
``````Hello, I have a question about the constant folding for fdiv instructions.
For the instruction "fdiv double 0.0, 0.0", the folded result is inf. I
think this should be nan. Can anyone tell me why it is not nan?

``````
``````
I think the specification says that it is "undefined" so any value will
do. inf is just as undefined as nan.

Reid.
``````

In IEEE Std 754-1985, subclause 7.2- Division by Zero, it says:

“If the divisor is zero and the dividend is a finite nonzero number, then the division by zero shall be signaled. The result, when no trap occurs, shall be a correctly signed (infinity symbol)(6.3).”

So LLVM is correct (assuming it handles signs correctly).

Jeff Cohen wrote:

Reid Spencer wrote:

``````
``````
``````Hello, I have a question about the constant folding for fdiv instructions.
For the instruction "fdiv double 0.0, 0.0", the folded result is inf. I
think this should be nan. Can anyone tell me why it is not nan?

``````
``````
I think the specification says that it is "undefined" so any value will
do. inf is just as undefined as nan.

Reid.
``````

In IEEE Std 754-1985, subclause 7.2- Division by Zero, it says:

“If the divisor is zero and the dividend is a finite nonzero number, then the division by zero shall be signaled. The result, when no trap occurs, shall be a correctly signed (infinity symbol)(6.3).”

So LLVM is correct (assuming it handles signs correctly).

Never mind… only applies if a non-zero number is being divided by zero.

Jeff Cohen wrote:

Jeff Cohen wrote:

Reid Spencer wrote:

``````
``````
``````Hello, I have a question about the constant folding for fdiv instructions.
For the instruction "fdiv double 0.0, 0.0", the folded result is inf. I
think this should be nan. Can anyone tell me why it is not nan?

``````
``````
I think the specification says that it is "undefined" so any value will
do. inf is just as undefined as nan.

Reid.
``````

In IEEE Std 754-1985, subclause 7.2- Division by Zero, it says:

“If the divisor is zero and the dividend is a finite nonzero number, then the division by zero shall be signaled. The result, when no trap occurs, shall be a correctly signed (infinity symbol)(6.3).”

So LLVM is correct (assuming it handles signs correctly).

Never mind… only applies if a non-zero number is being divided by zero.

The standard apparently doesn’t explicitly handle 0/0, but the position of the IEEE appears to be that it should yield a NaN of the appropriate sign. See

Jeff Cohen wrote:

The standard apparently doesn’t explicitly handle 0/0, but the position of the IEEE appears to be that it should yield a NaN of the appropriate sign. See

OK, it does explicitly handle it. My reading comprehension seems to be lacking right now

The above lists all operations that yield a NaN.

Sounds like a bug, please file it or fix it The code in question is VMCore/ConstantFold.cpp:654. It should produce the appropriately signed NaN instead of Inf.

-Chris