title: A bug in Matlab comparison?
body: <p>I write my own version <code>ismember</code>(<code>find_element</code>) in Matlab to check whether a row array <code>a</code> in matrix <code>b</code> or not, by comparing <code>a</code> with each row in <code>b</code>. If each element in <code>a</code> 'equals' each element of a row in <code>b</code>(if the absolute error is less than <code>Tol</code>), then return logic value 1 and row number.</p>
  
  <p>However, when I test my code, I find that Matlab will return <code>t=[1 1]</code> when compare <code>a=1.0e-11*[0.9063 0.0838]</code> with <code>B=[-1 0]</code>(<code>B</code> is the second row of <code>b</code>). Actually it gives correct absolute error <code>error=[1.0000 0.0000]</code>, and clearly <code>error(1)</code> is greater than <code>Tol=1e-6</code>. Did I find a bug in Matlab? Or is there any error in my code?</p>
  
  <p>The following is my <code>find_element</code> code:</p>
  
  <pre><code>function [Lia,Locb] = find_element(a,b)
  %decide whether a is in b or not(compare each row); if in, return row number
  %INPUT:
  %a: salar or row array
  %b: column array or matrix 
  %OUTPUT:
  %Lia: 1 if a is in b, 0 if not
  %Locb: location of a in b, row number if b is a matrix
  Tol = 1e-6; %set tolerance when compare elements
  Lia = 0;%initialization
  Locb = 0;
  
  t = zeros(size(a));%compare result of each element,logical array
  for i = 1:size(b,1) %loop through each row
      for j = 1:size(b,2) %compare each element in each row
          if abs(a(j)-b(i,j))&lt;Tol
              t(j) = 1;
          end
      end
      if t %all 1's
          Lia = 1;%find a in b
          Locb = i;%return row number
          %%%%%%%%%%%%%%%%%%%%%%%%
          %test outputs
          a
          B=b(i,:)
          error = abs(a-b(i,:))
          t
          %%%%%%%%%%%%%%%%%%%%%%%%
          break
      end
  end
  </code></pre>
  
  <p>The test code is :</p>
  
  <pre><code>a = [9.06319429228031e-12   8.37879678833309e-13];
  b = [0 1;-1 0;1 0;0 1];
  [Lia Locb] = find_element(a,b)
  </code></pre>
  
  <p>the output is:</p>
  
  <pre><code>a =
     1.0e-11 *
      0.9063    0.0838
  B =
      -1     0
  error =
      1.0000    0.0000
  t =
       1     1
  Lia =
       1
  Locb =
       2
  </code></pre>