Mail Archives: djgpp/1998/08/28/07:01:45
In a message which has reached me by email, but hasn't yet turned up on
our news server, Endlisnis wrote:
>Kevin Ashley wrote:
>
>> double dvar;
>> dvar = 25834242042;
>
> This line WILL work, I've already uploaded example code that shows this working.
I hadn't seen your example when I posted. However, I think there is
still some room for both to be correct. Your example was C++; I don't
program in that, but use C exclusively. I'm familiar with the C standard
but not with C++. As far as C is concerned, that constant is an integer
constant, which is then effectively cast to a double at compilation time.
If it's too big to fit in an int, the results are undefined.
GCC produces warnings at compilation time that the constant is too big
for an integer, and that it will end up being unsigned. I suspect it
must internally store the evaluation in a long long int, since it
does produce correct results despite the warnings, but this is definitely
compiler-specific behaviour and cannot be relied upon in general. I've
tried it on another compiler (ANSI-compatible but not GCC) and both
the double and the int end up equal to 64438266 (with a similar slew
of warnings.)
So, it may work, but if the target language is C it isn't right and
it isn't portable and sooner or later it may cause you problems. If
we're talking C++, I confess ignorance.
--------------------------------------------------------------------------
Kevin Ashley K DOT Ashley AT Ulcc DOT ac DOT uk
Special Projects Manager http://www.ulcc.ac.uk/staff/Kevin+Ashley
ULCC ...ukc!ncdlab!K.Ashley (but probably not any more)
This is not a signature
- Raw text -