float与double的精度


发现float与double的精度是依赖于平台的,与具体的硬件有关。在laptop算一个float数是34.xx,在workstation上就只是0.02xxx,正确的值应该是0。看来转成double还是保险些,不过郁闷的是输入数据都是float型的。

float:         4字节         6-7位有效数字         -3.4E-38     到     3.4E38    
double:     8字节         15~16位有效数字     -1.7E-308   到     1.7E308

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s