Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 that I search.

regards, Tobias

like image 599
Tobias Langner Avatar asked Mar 23 '11 09:03

Tobias Langner


People also ask

Which is the most commonly used floating-point data type?

The most commonly used floating point standard is the IEEE standard. According to this standard, floating point numbers are represented with 32 bits (single precision) or 64 bits (double precision).

What is the data type for a floating-point number?

The FLOAT data type stores double-precision floating-point numbers with up to 17 significant digits. FLOAT corresponds to IEEE 4-byte floating-point, and to the double data type in C. The range of values for the FLOAT data type is the same as the range of the C double data type on your computer.

What three types can store floating-point numbers?

There are three different floating point data types: float, double, and long double.

Is 0.0 a floating-point number?

In addition, there is a floating-point zero; depending on the implementation, there may also be a ``minus zero. '' If there is no minus zero, then 0.0 and -0.0 are both interpreted as simply a floating-point zero.


1 Answers

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

like image 61
Erik Avatar answered Oct 14 '22 08:10

Erik