Is there a floating point data type that converts without loss from int64?
is there a floating point data type in Visual C++ that has enough precision in the mantissa to hold an INT64?
Example it should be possible to do the following:
__int64 from = 0xFFFFFFFFFFFFFFFF;
mightyFP intermediate;
__int64 to;
intermediate = from;
to = intermediate;
assert(from == to);
where mightyFP is the unknown type t开发者_Go百科hat I search.
regards, Tobias
Short answer, no. long double
and double
have the same representation in visual studio. For x86 the size of both is 64 bits, which isn't enough to hold the full range of a 64-bit integer.
You need GMP
See
http://en.wikipedia.org/wiki/Long_double
http://en.wikipedia.org/wiki/Extended_precision
In short, there's a 10-byte "extended precision" type supported by all x86 cpus
(actually FPUs, later CPUs always use it for internal representations), which is commonly
referenced as "long double". But because of no support for this type in SSE,
modern compilers made it hard to access - it may be turned into an alias for "double"
depending on compiler options (like /Qlong-double, /Qpc80 in IntelC) and even target cpu.
Still, even if its really impossible to enable it in modern VS, writing a simple wrapper class with one-line asm implementations may be still an option.
There is quadruple-precision floating point (long double) but I'm not sure it's precise enough. You might want to use an arbitrary-precision library such as GMP or MPFR
精彩评论