This is unfortunately
not a bug. This is an issue with
floating point arithmetic and
floating point roundoff (google it), very well known issues when dealing with floating point numbers on a computer.
Here's why... Using Python, a language that properly represents floating points, you quickly see the following output:
>> 16.15
16.149999999999999
>>
This is the same in C:
main() {
double f = 16.15;
if (f == 16.15f)
printf("This value is 16.15\n");
else
printf("This value is not 16.15\n");
}
output: This value is not 16.15
Therefore we clearly see that rounding to 2 digits in Python would do the exact same thing it does in mIRC. We also see that C cannot do comparisons on certain floats. Is this a global programming language bug? Should C be changed? Should Python fix this too?
The answer is no, and it can't. The reason you see this is because of
floating point roundoff. 16.15 may seem like a perfectly natural number to you as a human who uses base-10 to represent numbers, but in a computer, where the number 16.15 is represented in base-2, this value is a repeating decimal. Short conclusion: there is no way to accurately represent the number 16.15 in a computer.
The only way to work around this would be for K to treat the number as a string and not convert it to a floating point in the computer which would mangle the value..
Here are some extra readings on the issue of comparing floating points, to see that you are not alone and so you can see why you will for the rest of your 32bit life see floating point issues in just about any language you use:
http://docs.python.org/tut/node16.htmlhttp://ajax.suaccess.org/ruby/comparing-floating-point-numbers/http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/280905http://en.wikipedia.org/wiki/Floating_pointHere's a math heavy one for the real geeks:
http://docs.sun.com/source/806-3568/ncg_goldberg.htmledit:
You can use this mIRC code as a workaround-- $roundp(16.15,1) == 16.2:
alias roundp {
var %p = $pos($1,.,1)
if (!%p) return $1
var %r, %p = $calc(%p + $2 + 1)
if ($mid($1, %p, 1) >= 5) {
%r = $left($calc($left($1, %p) + $&
$calc(10 ^ $+(-,$2))), $calc(%p - 1))
}
else {
%r = $left($1, $calc(%p - 1))
}
return $iif($right(%r,1) == ., $int(%r), %r)
}