Hi,
I am trying to evaluate this expression, it is supposed to give TRUE but, it is giving false.
sum((<a>5923.17</a>,<a>5956.29</a>,<a>5989.28</a>)) = <a>17868.74</a>
But, for this expression it is giving as expected.
sum((<a>5922.78</a>,<a>-5955.78</a>,<a>5988.74</a>)) = <a>5955.74</a>
Thanks
Ankit
Hi,
This looks like a general programming problem to me. It is always dangerous to ask for equality on real numbers. Because of a rounding problem in the calculation (because of the way computers work), the sum is not exactly equal to the number on the right hand-side.
The usual algorithm to compare real numbers for equality, up to say 3 decimal numbers, is the following, comparing integers instead (replace 1000 with e.g. 100 for 2 decimal places):
fn:round($n1 * 1000) = fn:round($n2 * 1000)
Regards,
Hi Ankit, the problem is with float rounding ...
sum((<a>5923.17</a>,<a>5956.29</a>,<a>5989.28</a>)) = 17868.739999999998
gives true() on my machine. As usual with floats you should probably apply a rounding policy to compare for exact equality. Regards, Marco.
On 12/03/2015 15:01, ankit kumar wrote:
Hi,
I am trying to evaluate this expression, it is supposed to give TRUE but, it is giving false.
sum((<a>5923.17</a>,<a>5956.29</a>,<a>5989.28</a>)) = <a>17868.74</a>
But, for this expression it is giving as expected.
sum((<a>5922.78</a>,<a>-5955.78</a>,<a>5988.74</a>)) = <a>5955.74</a>
Thanks
Ankit
basex-talk@mailman.uni-konstanz.de