Are these bugs for the clang compilers?

Hello everyone,

I found some questionable behaviors in the clang compiler.

I tried to calculate the smallest number in my machine with clang. I did it by looping as:

a = a / 1.73

In g++, after 1358 loops, I found that a = 4.94066E-324, and the value of a never changes from loop 1358 till the end 1500 loop.

It is questionable for me that a non zero real number here a = 4.94066E-324 divided by a non zero and non one real number here 1.73 will keep the same value. The phenomenon seems to the qualification of the ground state energy in a quantum system.

Is this bug for the clang compiler?

I tested my code with, g++ (Apple LLVM version 10.0.0, clang-1000.10.44.4) on Macintosh. I also tried a = a / 1.7, a = a / 1.77.

All have similar results. A ground state qualification and unchanged value of a.

I guess that it is related to the binary system used by the computer system.

Here with my codes.

Best wishes
Tianyou Yi
Postdoc researcher in National Tsing Hua University

Hi Tianyou,

I am not enough of a physicist to know what “the qualification of the ground state energy in a quantum system” means, but this does not sound like a Clang bug to me. You did not say whether a in your example is a float or a double, but the minimum legal values for these types are the constants FLT_MIN and DBL_MIN. There is no need to try to compute them. Exceeding the range of values representable in a type — [FLT_MIN, FLT_MAX] or [DBL_MIN, DBL_MAX] — is undefined behavior, so the compiler is free to emit anything.

Thanks,
Matt