Machine Epsilon - Really?

Function zeros do not necessarily fall on the discretely desirable points. For example, the Colinear checking function shows a pattern of zeros in yellow, positives in red, and negatives in blue.


require 'tk'

root = TkRoot.new
$canvas = TkCanvas.new(root) { 
  width  400
  height 400
}
$canvas.pack

# EPSILON: machine epsilon
# 0 1           12                                                   64
# +-+-----------+----------------------------------------------------+
# |0|01111001011|0000000000000000000000000000000000000000000000000000|
# +-+-----------+----------------------------------------------------+

d = 6        # graphics tile size
n = 2**6     # number of tiles in x/y axis
e = 2**(-52) # ieee 754 machine epsilon 2.2204460492503131E-16
t = e*0.1    # increment of x/y parameters

x0 = y0 = 0.123456  # point0
x1 = y1 = 0.987654  # point1

for i in 0...n
  x = i*t + 0.5
  for j in 0...n
    y = j*t + 0.5
    val = (x0-x)*(y1-y)-(x1-x)*(y0-y)  # check colinearity of (x,y)
    clr = val > 0 ? 'red' : val < 0 ? 'navy' : 'yellow'
    TkcRectangle.new $canvas, d*i, d*j, d*(i+1), d*(j+1), {:fill=>clr}
  end
end

Tk.mainloop