not a bug.
[~, idx] = min(abs(vec - D));
You can see that the closest value to D in vec is about 2.22e-16 less than D.
Your colon operator is operating like this:
if new > stop; break; end
Now if (1.59 - 1) were exactly divisibile by the binary double precision representation of 0.005 and assuming that start (1.0) is exactly representable in binary double precision, then under those circumstances 1.59 exactly would eventually be reached.
However... the binary double precision representation of 0.005 is 0.005000000000000000104083408558608425664715468883514404296875 exactly. Binary double precision is not able to represent 0.001 exactly . And those differences add up.
The reason that binary double precision is not able to represent 0.001 exactly is the same as the reason that a finite decimal floating point representation cannot exactly represent 1/3 or 1/7 . Suppose that you had a system that stored 10 decimal digits, then 1/3 would be 0.3333333333 . Add another of the same and you would get 0.6666666666 . Add the third value on and you would get 0.9999999999 -- which is not 1.0000000000 ! Algebraic rational 1/3 can only be exactly represented in a finite number of digits if the digit base is divisible by 3, which is not the case for decimal (base 10). Algebraic rational 1/10 can only be exactly represented in a finite number of digits i the digit base is divisible by 10, which is not the case for binary (base 2.)
You need to learn this rule:
Never compare floating point numbers for equality if the floating point numbers might have been calculated different ways. Even just very slight differences in computation like .3 - .2 - .1 versus .3 - .1 - .2 make a difference in floating point calculations.