如何以最大精度存储双倍

时间:2021-11-27 17:10:03

I'm a bit stucked with storing number with maximum available precision:

我有点坚持使用最大可用精度存储数字:

double tmp = 569.232306826889043804840184748172760009765625L;

I'm trying to print it on the screen:

我正试图在屏幕上打印它:

printf("%0.52f\n", tmp);

And that's what I've got:

这就是我所拥有的:

569.2323068268890400000000000000000000000000000000000000

Is this the maximum precision which I can achieve?

这是我能达到的最高精度吗?


P.S. I'm using Visual Studio 2008

附:我正在使用Visual Studio 2008

2 个解决方案

#1


15  

A double is usually stored in IEEE 754 binary64 format.

double通常以IEEE 754 binary64格式存储。

A binary64 has 52 bits of precision, not 52 decimal digits - this is equivalent to at most 17 decimal digits, which is what you're displaying.

binary64具有52位精度,而不是52位十进制数 - 这相当于最多17位十进制数,这就是您要显示的数字。


Is this the maximum precision which I can achieve?

这是我能达到的最高精度吗?

Some platforms may provide a long double which is actually bigger than a double, but yours doesn't seem to.

有些平台可能会提供一个长双倍,实际上比双倍大,但你的似乎并不是。

If you want more precision, you can either use a library that exposes some larger/more precise type supported by your hardware (such as the 80-bit extended double), or an arbitrary-precision library that works in software.

如果需要更高的精度,可以使用一个库,该库可以显示硬件支持的更大/更精确的类型(例如80位扩展双精度型),也可以使用在软件中工作的任意精度库。

#2


6  

That is the precision of type double in your C implementation. Conformant C implementations also have a type long double, which may offer greater precision.

这是C实现中double类型的精度。符合C的实现也有一个long double类型,可以提供更高的精度。

If you need more precision than that then there are numeric libraries that provide arbitrary-precision numeric types and functions to operate on them. The GNU Multiple Precision Arithmetic Library is one such; it works on many platforms, including the ones relevant to you -- Win32 and Win64.

如果您需要更高的精度,那么有一些数字库可以提供任意精度的数字类型和函数来对它们进行操作。 GNU多精度算术库就是这样的一个;它适用于许多平台,包括与您相关的平台 - Win32和Win64。

#1


15  

A double is usually stored in IEEE 754 binary64 format.

double通常以IEEE 754 binary64格式存储。

A binary64 has 52 bits of precision, not 52 decimal digits - this is equivalent to at most 17 decimal digits, which is what you're displaying.

binary64具有52位精度,而不是52位十进制数 - 这相当于最多17位十进制数,这就是您要显示的数字。


Is this the maximum precision which I can achieve?

这是我能达到的最高精度吗?

Some platforms may provide a long double which is actually bigger than a double, but yours doesn't seem to.

有些平台可能会提供一个长双倍,实际上比双倍大,但你的似乎并不是。

If you want more precision, you can either use a library that exposes some larger/more precise type supported by your hardware (such as the 80-bit extended double), or an arbitrary-precision library that works in software.

如果需要更高的精度,可以使用一个库,该库可以显示硬件支持的更大/更精确的类型(例如80位扩展双精度型),也可以使用在软件中工作的任意精度库。

#2


6  

That is the precision of type double in your C implementation. Conformant C implementations also have a type long double, which may offer greater precision.

这是C实现中double类型的精度。符合C的实现也有一个long double类型,可以提供更高的精度。

If you need more precision than that then there are numeric libraries that provide arbitrary-precision numeric types and functions to operate on them. The GNU Multiple Precision Arithmetic Library is one such; it works on many platforms, including the ones relevant to you -- Win32 and Win64.

如果您需要更高的精度,那么有一些数字库可以提供任意精度的数字类型和函数来对它们进行操作。 GNU多精度算术库就是这样的一个;它适用于许多平台,包括与您相关的平台 - Win32和Win64。