<< Travel Log: On the Road in Miami - Part IV | Home | Design: Xpages or Flex?>>
Domino: 8.5 Precision Still Lacking
Fri 6 Mar 2009
I guess it's been a known issue for some time now that math in LotusScript lacks some precision. I was able to recreate this on this sunny morning in 8.5 using a simple button in a rich text field with some script behind it.
Below are the results of summing and recombining the value 1.23, typed as a double, 100 times.
--- Scroll down for precision loss example ---
2.46
4.92
7.38
9.84
12.3
14.76
17.22
19.68
22.14
24.6
27.06
29.52
31.98
34.44
36.9
39.36
41.82
44.28
46.74
49.2
51.66
54.12
56.5799999999999 <--- eh?
59.0399999999999 <--- huh?
61.4999999999999 <--- doh!
63.9599999999999 <--- etc.
66.4199999999999
68.8799999999999
71.3399999999999
73.8 <--- and suddenly...
76.26
78.72
81.18
83.64
86.1
88.56
91.02
93.48
95.94
98.4
100.86
103.32
105.78
108.24
110.7
113.16
115.62
118.08
120.54
123
125.46
127.92
130.38
132.84
135.3
137.76
140.22
142.68
145.14
147.6
150.06
152.52
154.98
157.44
159.9
162.36
164.82
167.28
169.74
172.2
174.66
177.12
179.58
182.04
184.5
186.96
189.42
191.88
194.34
196.8
199.26
201.72
204.18
206.639999999999
209.099999999999
211.559999999999
214.019999999999
216.479999999999
218.939999999999
221.399999999999
223.859999999999
226.319999999999
228.779999999999
231.239999999999
233.699999999999
236.159999999999
238.619999999999
241.079999999999
243.539999999999
245.999999999999
248.459999999999
Here are the same results as rendered by MS Excel.
4.92
7.38
9.84
12.3
14.76
17.22
19.68
22.14
24.6
27.06
29.52
31.98
34.44
36.9
39.36
41.82
44.28
46.74
49.2
51.66
54.12
56.58 <---- OK
59.04 <---- OK
61.5 <---- OK
63.96 <---- OK
66.42 <---- OK
68.88 <---- OK
71.34 <---- OK
73.8
76.26
78.72
81.18
83.64
86.1
88.56
91.02
93.48
95.94
98.4
100.86
103.32
105.78
108.24
110.7
113.16
115.62
118.08
120.54
123
125.46
127.92
130.38
132.84
135.3
137.76
140.22
142.68
145.14
147.6
150.06
152.52
154.98
157.44
159.9
162.36
164.82
167.28
169.74
172.2
174.66
177.12
179.58
182.04
184.5
186.96
189.42
191.88
194.34
196.8
199.26
201.72
204.18
206.64
209.1
211.56
214.02
216.48
218.94
221.4
223.86
226.32
228.78
231.24
233.7
236.16
238.62
241.08
243.54
246
So, what's happening here? Let's look at 54.12 + 1.23 + 1.23. Calc.exe produces 56.58, as does excel. Even increasing the decimal place precision in Excel I get 56.58000000. But LotusScript produces 56.57999999, shaving .00000001 off. What's strange is this is consistent. I can run the test over and over again and LS produces the same result.
I can't think of a good reason for this to happen, but suffice to say, do not launch your satellites with LS derived flight parameters. What's unfortunate is that this can make you, the developer, look bad unless you're prepared to handle it. Happily, this small loss of precision does not produce inaccurate rounding results, so if you round your output in LS to two decimal places, it behaves properly.
2.46
4.92
7.38
9.84
12.3
14.76
17.22
19.68
22.14
24.6
27.06
29.52
31.98
34.44
36.9
39.36
41.82
44.28
46.74
49.2
51.66
54.12
56.58 <--- rounds correctly
59.04
61.5
63.96
66.42
68.88
71.34
73.8
76.26
78.72
81.18
83.64
86.1
88.56
91.02
93.48
95.94
98.4
100.86
103.32
105.78
108.24
110.7
113.16
115.62
118.08
120.54
123
125.46
127.92
130.38
132.84
135.3
137.76
140.22
142.68
145.14
147.6
150.06
152.52
154.98
157.44
159.9
162.36
164.82
167.28
169.74
172.2
174.66
177.12
179.58
182.04
184.5
186.96
189.42
191.88
194.34
196.8
199.26
201.72
204.18
206.64
209.1
211.56
214.02
216.48
218.94
221.4
223.86
226.32
228.78
231.24
233.7
236.16
238.62
241.08
243.54
246
248.46