On 2/13/2012 7:41 AM, Alex Vinokur wrote:

> Hi,

>

> unsigned long a = -1;

> double b = a;

> unsigned long c = b;

>

> Model 32-bits: a == c

> Model 64-bits: a != c

>

>

> It is not a compiler bug for 64-bits.

>

> Is it a design bug of C/C++ languge for 64-bits?
Whether the language design is faulty seems a matter of opinion.

However, part of the "spirit of C" is to stay fairly close to the

hardware. Since hardware that offers 64 bits of precision in the

floating-point format used for `double', some loss of precision in

`b = a' must be expected.

The language *could* have been defined to raise an exception

whenever a floating-point operation delivers an inexact result, but

that would have meant raising such exceptions for a large fraction

of all F-P calculations, perhaps many times in a single expression.

Or the language could have left the inexact conversion entirely

undefined, in which case there'd be no reason to expect `a == c'

(or even that the execution would get that far). The behavior

actually chosen (conversion yields one of the two representable

neighbors) seems fairly benign, not something I'd call a bug. But,

as I say, that's a matter of opinion.

(The language *could* have been defined to deliver exact F-P

results for all calculations, widening the representation at need.

That's the approach used on the Starship Enterprise, where Kirk

crippled the computer by asking it to calculate pi ...)

--

Eric Sosman

http://www.velocityreviews.com/forums/(E-Mail Removed)d