SAS中文论坛

标题: 胡说 - 关于SAS浮点数 [打印本页]

作者: shiyiming    时间: 2010-7-13 21:00
标题: 胡说 - 关于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]
作者: shiyiming    时间: 2010-7-14 10:40
标题: 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?




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2