I grew up on COBOL and mainframe Assembler. I loved packed decimal numbers because you always knew what you had. I HATE floating point numbers. I first stumbled upon this issue accidentally while learning C. The same issue exists in Java. And SAS.
I don't have time to elaborate right now. So I just want to capture the problem. Here is the SAS log. compare variables (e and f), (c and h), and (b and g). In particular, note my use of +1.E-10. Warning ... +1.E-11 gives different results.
1 data _null_;
2 a = 400.4444;
3 i = 4;
4 b = int(a * 10 ** i) / (10 ** i);
5 c = (a = b);
6 d = a * 10 ** i;
7 e = int(a * 10 ** i);
8 f = int(a * 10 ** i + 1.E-10);
9 g = int(a * 10 ** i + 1.E-10) / (10 ** i);
10 h = (a = g);
11 put a= i= b= c= d= e= f= g= h=;
12 run;
a=400.4444 i=4 b=400.4443 c=0 d=4004444 e=4004443 f=4004444 g=400.4444 h=1
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment