At 16:18 -0700 4/15/05, gcomnz wrote: >More questions stemming from cookbook work... Decimal Comparisons: > >The most common recipe around for comparisons is to use sprintf to cut >the decimals to size and then compare strings. Seems ugly. > >The non-stringification way to do it is usually along the lines of: > >if (abs($value1 - $value2) < abs($value1 * epsilon)) > >(From Mastering Algorithms with Perl errata) > >I'm wondering though, if C<$value1 == $value2> is always wrong (or >almost always wrong) then should it be smarter and: > SNIP >Marcus Adair
I have longed for an OO class that might be called "measurement". An object would include a float, a unit of measure, and an estimate of accuracy. Mathematical operations would be overloaded so that the result of a calculation would appropriately handle propagation of the argument's accuracies into the result. It might even do unit conversions but that's another subject. Coercion of a float into a measurement would be automatic with infinite precision assumed. Given the new class it is easy to adjust comparison operators to calculate "within experimental error". -- --> Life begins at ovulation. Ladies should endeavor to get every young life fertilized. <--