Thanks all.
I'd suspected a roundoff issue, and thought I'd see evidence of this by using 'print' or 'printf' on $a[2] (without specifying how many decimal places). Since I got 2 or 2.000000, I discarded that thought. But specifying several decimal places out (i.e. 'printf("%.20f", $a[2])' ) reveals what the problem is.