For or_less and or_more, $y is ignored if passed. For infinite, neither $x nor $y is used; "infinite" should be the sole argument. The first two arguments can be reversed for more_than and less_than, to be more English-like.

An offset is very much like a plus_or_minus tolerance, but its center value is not necessarily the midpoint between its extremes. This is significant for comparisons and numifications of the tolerance. Given the following two tolerances:

An intersection with a normal number will yield that number, if it is within the tolerance.

tolerance union

A tolerance | a tolerance or number is the union of the two. Unions allow multiple tolerances, whether they intersect or not, to be treated as one. See Number::Tolerant::Union for more information.

EXTENDING

This feature is slighly experimental, but it's here.

New tolerance types may be written as subclasses of Number::Tolerant::Type, providing the interface described in its documentation. They can then be enabled or disabled with the following methods:

enable_plugin

Number::Tolerant->enable_plugin($class_name);

This method enables the named class, so that attempts to create new tolerances will check against this class. Classes are checked against "validate_plugin" before being enabled. An exception is thrown if the class does not appear to provide the Number::Tolerant::Type interface.

disable_plugin

Number::Tolerant->disable_plugin($class_name);

This method will disable the named class, so that future attempts to create new tolerances will not check against this class.

validate_plugin

Number::Tolerant->validate_plugin($class_name);

This method checks (naively) that the given class provides the interface defined in Number::Tolerant::Type. If it does not, an exception is thrown.

Create a factory so that you can simultaneously work with two sets of plugins.

This one is very near completion. There will now be two classes that should be used: Number::Tolerant::Factory, which produces tolerances, and Number::Tolerant::Tolerance, which is a tolerance. Both will inherit from N::T, for supporting old code, and N::T will dispatch construction methods to a default factory.

SEE ALSO

The module Number::Range provides another way to deal with ranges of numbers. The major differences are: N::R is set-like, not range-like; N::R does not overload any operators. Number::Tolerant will not (like N::R) attempt to parse a textual range specification like "1..2,5,7..10" unless specifically instructed to. (The valid formats for strings passed to from_string does not match Number::Range exactly. See TODO.)

The Number::Range code:

$range = Number::Range->new("10..15","20..25");

Is equivalent to the Number::Tolerant code:

$range = Number::Tolerant::Union->new(10..15,20..25);

...while the following code expresses an actual range:

$range = tolerance(10 => to => 15) | tolerance(20 => to => 25);

THANKS

Thanks to Yuval Kogman and #perl-qa for helping find the bizarre bug that drove the minimum required perl up to 5.8

Thanks to Tom Freedman, who reminded me that this code was fun to work on, and also provided the initial implementation for the offset type.

AUTHOR

Ricardo Signes <rjbs@cpan.org>

CONTRIBUTORS

Alexandre Mestiashvili <alex@biotec.tu-dresden.de>

Karen Etheridge <ether@cpan.org>

Michael Carman <mjcarman@cpan.org>

Ricardo SIGNES <rjbs@codesimply.com>

Smylers <Smylers@stripey.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2004 by Ricardo Signes.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Module Install Instructions

To install Number::Tolerant, simply copy and paste either of the commands in to your terminal

As a valued partner and proud supporter of MetaCPAN, StickerYou is
happy to offer a 10% discount on all Custom Stickers,
Business Labels, Roll Labels,
Vinyl Lettering or Custom Decals. StickerYou.com
is your one-stop shop to make your business stick.
Use code METACPAN10 at checkout to apply your discount.