A Floating-point Filter [1] provides a Numeric type that wraps another
Numeric type, but defers its computation, instead providing a floating
point (Double) approximation. For some operations, like signum,
comparisons, equality checks, toFloat, etc, the Double approximation may
be used to compute the result, rather than having to compute the exact value.
An FpFilter can generally be used with any Ring numeric type (also
supports EuclideanRing, Field, and NRoot). However, it should be
kept in mind that FpFilter knows nothing about the type its wrapping and
assumes that, generally, it is more accurate than it is. When an FpFilter
cannot determine an answer to some predicate exactly, it will defer to the
wrapped value, so it probably doesn't make sense to wrap Ints, when an
Int will overflow before a Double!
Good candidates to wrap in FpFilter are BigInts, Rationals,
BigDecimals, and Algebraic. Note that while Algebraic has an
internal floating-point filter, this still provides benefits. Namely, the
operator-fusion and allocation removal provided by the macros can make for
much faster hot paths.
Note: Both equals and hashCode will generally force the exact computation.
They should be avoided (prefer === for equals)... otherwise why use
bother?
A Floating-point Filter [1] provides a
Numerictype that wraps anotherNumerictype, but defers its computation, instead providing a floating point (Double) approximation. For some operations, likesignum, comparisons, equality checks, toFloat, etc, theDoubleapproximation may be used to compute the result, rather than having to compute the exact value.An
FpFiltercan generally be used with any Ring numeric type (also supports EuclideanRing, Field, and NRoot). However, it should be kept in mind thatFpFilterknows nothing about the type its wrapping and assumes that, generally, it is more accurate than it is. When anFpFiltercannot determine an answer to some predicate exactly, it will defer to the wrapped value, so it probably doesn't make sense to wrapInts, when anIntwill overflow before aDouble!Good candidates to wrap in
FpFilterare BigInts, Rationals, BigDecimals, and Algebraic. Note that while Algebraic has an internal floating-point filter, this still provides benefits. Namely, the operator-fusion and allocation removal provided by the macros can make for much faster hot paths.Note: Both equals and hashCode will generally force the exact computation. They should be avoided (prefer
===for equals)... otherwise why use bother?[1] Burnikel, Funke, Seel. Exact Geometric Computation Using Cascading. SoCG 1998.