Do you ever have need to normalize values that are approaching, but not quite zero, like -1.83691e-016, that is, have it evaluated as zero if it's smaller than an arbitrary threshold?
I had a colleague who needed something like this so I thought I'd share it.
(defun Normalize ( x )
(cond
((zerop x) x)
((eq 'int (type x)) x)
((equal 0 x 1e-15) 0.0)
(x)
)
)
(Normalize 0)
==> 0
(Normalize 0.0)
==> 0.0
(Normalize 1e-5)
==> 1.0e-005
(Normalize -1.83691e-016)
==> 0.0
(mapcar 'Normalize '(1.0 -1.83691e-016 0.0))
==> (1.0 0.0 0.0)[/color]
The idea is that it won't change ints to reals and vice versa, but it does return 0.0 for minuscule values.
Obviously the 1e-15 fuzz factor is subjective.
What would you use?
Any other thoughts?