SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 643|回复: 1
打印 上一主题 下一主题

胡说 - 关于SAS浮点数

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2010-7-13 21:00:25 | 只看该作者

胡说 - 关于SAS浮点数

感谢: jingju11,shiyiming,ahuige
[code:xis0tj0g]data _null_;
  x=7.3;
  x=x+0.1;
  put x=;
  if x EQ 7.4 then put "equals 7.4";
  else put "not equal to 7.4";
run;
/*x=7.4*/
/*not equal to 7.4*/
/*X的值是7.4,但为什么put出来的是不等于呢*/
data _null_;
  x=7.3;
  x=x+0.2;
  put x=;
  if x EQ 7.5 then put "equals 7.4";
  else put "not equal to 7.4";
run;
/*x=7.5*/
/*equals 7.4*/
/*X的值是7.5,怎么put出来的又是等于呢*/[/code:xis0tj0g]
[img:xis0tj0g]http://www.mysas.net/sns/attachment/201007/6/12_1278378094pRxh.jpg[/img:xis0tj0g]
[img:xis0tj0g]http://www.mysas.net/sns/attachment/201007/6/12_1278378098uaU7.jpg[/img:xis0tj0g]
[img:xis0tj0g]http://www.mysas.net/sns/attachment/201007/6/12_1278378101s9r9.jpg[/img:xis0tj0g]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2010-7-14 10:40:51 | 只看该作者

Re: 胡说 - 关于SAS浮点数

That is to say 7.3 was stored as a approximate binary-system value, and so was 0.1. Then 7.3+0.1 is approximate value plus approximate value, indeed it will not equal 7.4(also a approximate value). However 7.5 can be stored as a exact binary-system, so 7.3+0.2 can equal 7.5.

In a word, what we see in SAS dataset is not what it is stored in memory.

Am I right?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-4 01:38 , Processed in 0.069756 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表