How many significant bits in a UINT64? 64 I'd guess.
How many significant bits in a double? Less than 64.
What do you want to do if the UINT64 doesnt fit?
Main Topics
Browse All TopicsDear Experts,
MSVC6 can not internally convert unsigned __int64 to double. However, VC.NET 2003 (among others) can do the conversion. In addition GCC for Intel Architectures can internally convert unsigned long long, also 64-bit unsigned integer, to double.
Does anyone have a good work-around for MSVC6? I'm using the code snippet shown below, but I find it unsatisfactory. First of all, the code does not use the full range, since for MSVC6 there is a conversion to signed 64-bit integer, and also the snippet is ugly and disturbs the more 'normal' use of static_cast<double>(UINT64
Thanks for your help.
Sincerely, Chris.
inline double UINT64_to_double(const UINT64& u)
{
#if defined (_MSC_VER) && (_MSC_VER <= 1200)
return static_cast<double>(static
#else
return static_cast<double>(u);
#endif
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
> What do you want to do if the UINT64 doesnt fit?
It is a floating point representation. See the following:
--------8<--------
#include <iostream>
#include <limits>
#include <iomanip>
typedef __int64 UINT64;
template<class T> void info(const char *name)
{
std::cout
<< name
<< std::scientific
<< std::setprecision(3) /* Good enough for the max */
<< " data bits = " << std::numeric_limits<T>::di
<< ", max = " << static_cast<double>(std::n
<< '\n';
}
#define INFO(T) info<T>(#T)
int main()
{
INFO(UINT64);
INFO(double);
}
--------8<--------
UINT64 data bits = 63 max = 9.223e+018
double data bits = 53 max = 1.798e+308
double has a greater range because it uses an exponent.
Thank you for all of these clear responses. Indeed, I had never really taken the time to clearly think about this conversion. The 53 bits of the ieee754 double can not identically represent UINT64.
In fact, this recognition has caused me to have to re-think the developmental issue to which this question pertains. The development issue involves converting result = (u64 * 1000000) / scale. Previously I had done a 'cheap' conversion using the cast to double of 1000000.0. But upon reflection, I noted that I actually want to do an exact conversion. This is no problem, but I will have to dig into the tools for extended integers.
Thanks everyone for clearing up this issue.
All of the responses were helpful and I must split the points equally. I can't figure out how to increase the points.
This issue is, in my opinion, now closed.
Sincerely, Chris.
It might be worth your while looking at boost's big_int - see http://groups.yahoo.com/gr
Business Accounts
Answer for Membership
by: rstaveleyPosted on 2004-09-15 at 04:49:23ID: 12063429
This should do it on an Intel platform (i.e. assuming little-endian):
umeric_lim its<UINT32 >::max())+ 1.0;
inline double UINT64_to_double(const UINT64& u)
{
#if defined (_MSC_VER) && (_MSC_VER <= 1200)
static const double multiplier = static_cast<double>(std::n
const UINT32* p_low = reinterpret_cast<const UINT32*>(&u);
const UINT32* p_high = p_low+1;
return *p_high*multiplier + *p_low;
#else
return static_cast<double>(u);
#endif
}