如何定义高精度日期类型 [英] How to Define High-precision Date type

查看:69
本文介绍了如何定义高精度日期类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



内置日期类型C的精度非常低。即使使用long

双浮点型或双浮点型,我们也只能在小数点后使用12或16位

。如果我们想使用

高精度数字,例如

小数点后50位数字,我们该怎么办?我们可以定义用户日期类型吗?

Hi,
The precision of built-in date type of C is very low. Even using long
double float type or double float type, we can only use 12 or 16 digits
after the decimal point. What can we do if we want to use
high-precision number such as the number with 50 digits after the
decimal point. Can we define a user date type?

推荐答案

文章< 11 ************ **********@i39g2000cwa.googlegroups .com> ;,

Donkey< ne ******** @ hotmail.com>写道:
In article <11**********************@i39g2000cwa.googlegroups .com>,
Donkey <ne********@hotmail.com> wrote:
内置日期类型C的精度非常低。即使使用长双浮点型或双浮点型,我们也只能在小数点后使用12或16位数。如果我们想要使用
高精度数字,例如小数点后的50位数字,我们该怎么办?我们可以定义一个用户日期类型吗?
The precision of built-in date type of C is very low. Even using long
double float type or double float type, we can only use 12 or 16 digits
after the decimal point. What can we do if we want to use
high-precision number such as the number with 50 digits after the
decimal point. Can we define a user date type?




不,如果你想要更长的编译器提供的精度,

那么你要么自己编写计算程序,

或者找一个预先编写的扩展精度库并使用它。


-

编程就是在您忙于制定其他计划时发生的事情。



No, if you want longer precision that is provided by the compiler,
then you either have to program the calculation routines yourself,
or else find a pre-written extended precision library and use it.

--
Programming is what happens while you''re busy making other plans.


" Donkey" <是ne ******** @ hotmail.com>写道:
"Donkey" <ne********@hotmail.com> writes:
内置日期类型C的精度非常低。即使使用长双浮点型或双浮点型,我们也只能在小数点后使用12或16位数。如果我们想要使用
高精度数字,例如小数点后的50位数字,我们该怎么办?我们可以定义用户日期类型吗?
The precision of built-in date type of C is very low. Even using long
double float type or double float type, we can only use 12 or 16 digits
after the decimal point. What can we do if we want to use
high-precision number such as the number with 50 digits after the
decimal point. Can we define a user date type?




使用GNU GMP等库(google it)。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http:// www。 ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



Use a library such as GNU GMP (google it).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Donkey写道:

内置日期类型C的精度是非常低。即使使用长双浮点型或双浮点型,我们也只能在小数点后使用12或16位数。如果我们想要使用
高精度数字,例如小数点后的50位数字,我们该怎么办?我们可以定义用户日期类型吗?
Hi,
The precision of built-in date type of C is very low. Even using long
double float type or double float type, we can only use 12 or 16 digits
after the decimal point. What can we do if we want to use
high-precision number such as the number with 50 digits after the
decimal point. Can we define a user date type?




从太阳到地球的平均距离约为149.598e6 km。

将DBL_DIG用于15.(1e-15 * sun_to_earth_distance)约为.15毫米。

小心假设是说明15位有效数字(小数点后的数字为
)没有意义)是非常低。当15个显着的

十进制数字允许表示从太阳到地球的平均距离为0.15毫米,这确实是高精度。


更高精度变得有意义的地方在修订中

导致一些算术运算。您可能需要更高的精度

,比如矩阵求逆。关于这一点有几点要说:

1)long double *可能*足够,或者

2)存在许多用于以更高精度进行算术运算的包,或者

3)你犯了一个严重错误。

积分(3)很重要。如果我发现我的问题需要的价值超过

长双打的能力(18个有效数字和一个范围

1e-4391到1e4392我的实施),我会认真的考虑

我是否有病理数据或需要修复的算法。



The average distance from the sun to Earth is about 149.598e6 km.
Supose DBL_DIG to be 15. A (1e-15 * sun_to_earth_distance) is about .15 mm.
Be careful is assuming stating that 15 significant digits ("digits after
the decimal point" is meaningless) is "very low". When 15 significant
decimal digits allows expressing the average distance from the sun to
the earth to with 0.15 mm, that is high accuracy, indeed.

The place that greater precision becomes meaningful is in intermendiate
results in some arithmetic operations. You might want higher precision
in, say, matrix inversion. There are several things to say about this:
1) long double *might* be sufficient, or
2) many packages exist for doing arithmetic with greater precision, or
3) you are making a serious mistake.
Point (3) is significant. If I found my problem required values beyond
the capabilities of long doubles (18 significant figures and a range of
1e-4391 to 1e4392 on my implementation), I would seriously consider
whether I had pathologogical data or an algorithm that needed fixing.


这篇关于如何定义高精度日期类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆