Ian Collins wrote in message...
James Kanze wrote:
[snip]
Nonsense. Int's convert implicitly to double, and it's a
non-lossy conversion, so there's not even the slightest excuse
for a warning.
Just curious, is it guaranteed to be non-lossy? I'd have thought it
depends on the size of int whether all value of int are exactly
representable as a double.
[ being in a 'scatter-brained' mood and only haveing a single-brain-cell,
I'd read the following with great caution! <G]
Since the standard only qualifies an 'int' type to 16 bits, I'd say "yes"
(IMHO).
If a system increases an 'int' to 32 bits (one bit being the sign bit), and
does not increase the double's bits, I'd NOT buy that system!!
[ I think you are thinking about the fractional part of the double (which
will be zero(s) for an int conversion). See below (IntMax).]
Test your own system:
#include <limits// and <iostream>
{
using std::cout // for NG post
cout<<" dbl max() ="
<< std::numeric_limits<double>::max()<<std::endl;
cout<<" int max() ="<< std::numeric_limits<int>::max()<<std::endl;
cout <<" dbl digits ="
<<(std::numeric_limits<double>::digits)<<std::endl ;
cout <<" int digits ="
<<(std::numeric_limits<int>::digits)<<std::endl;
double IntMax( std::numeric_limits<int>::max() );
cout <<" double IntMax ="<<IntMax<<std::endl;
// assumes your system has type 'long long' ( like GNU GCC).
cout<<" LL max() ="
<< std::numeric_limits<long long>::max()<<std::endl;
cout <<" LL digits ="
<<(std::numeric_limits<long long>::digits)<<std::endl;
double LLMax( std::numeric_limits<long long>::max());
cout <<" double LLMax ="<<LLMax<<std::endl;
}
/* - output (win98se, P4) -
dbl max() =1.79769e+308
int max() =2147483647
dbl digits =53
int digits =31
double IntMax =2147483647.000000
LL max() =9223372036854775807
LL digits =63
double LLMax =9223372036854775800.000000
*/
Note the loss in 'LLMax'. (trying to stuff 63bits into 53bits)
If you are not sure, use a 'long double'! <G>
cout<<" LD digits ="
<<(std::numeric_limits<long double>::digits)<<std::endl;
// LD digits =64
Or, were you asking if the C++ standards committee "guarantees it"?
[ Ok, the laugh is NOT affecting me, blah! <GMind yer manners or i'll
attach something! <G]
--
Bob R
POVrookie