1Number::Tolerant::UnionU(s3e)r Contributed Perl DocumentaNtuimobner::Tolerant::Union(3)
2
3
4
6 Number::Tolerant::Union - unions of tolerance ranges
7
9 version 1.710
10
12 use Number::Tolerant;
13
14 my $range1 = tolerance(10 => to => 12);
15 my $range2 = tolerance(14 => to => 16);
16
17 my $union = $range1 | $range2;
18
19 if ($11 == $union) { ... } # this will happen
20 if ($12 == $union) { ... } # so will this
21
22 if ($13 == $union) { ... } # nothing will happen here
23
24 if ($14 == $union) { ... } # this will happen
25 if ($15 == $union) { ... } # so will this
26
28 Number::Tolerant::Union is used by Number::Tolerant to represent the
29 union of multiple tolerances. A subset of the same operators that
30 function on a tolerance will function on a union of tolerances, as
31 listed below.
32
34 This library should run on perls released even a long time ago. It
35 should work on any version of perl released in the last five years.
36
37 Although it may work on older versions of perl, no guarantee is made
38 that the minimum required version will not be increased. The version
39 may be increased for any reason, and there is no promise that patches
40 will be accepted to lower the minimum required perl.
41
43 new
44 my $union = Number::Tolerant::Union->new(@list_of_tolerances);
45
46 There is a "new" method on the Number::Tolerant::Union class, but
47 unions are meant to be created with the "|" operator on a
48 Number::Tolerant tolerance.
49
50 The arguments to "new" are a list of numbers or tolerances to be
51 unioned.
52
53 Intersecting ranges are not converted into a single range, but this may
54 change in the future. (For example, the union of "5 to 10" and "7 to
55 12" is not "5 to 12.")
56
57 options
58 This method will return a list of all the acceptable options for the
59 union.
60
61 Overloading
62 Tolerance unions overload a few operations, mostly comparisons.
63
64 numification
65 Unions numify to undef. If there's a better idea, I'd love to hear
66 it.
67
68 stringification
69 A tolerance stringifies to a short description of itself. This is
70 a set of the union's options, parentheses-enclosed and joined by
71 the word "or"
72
73 equality
74 A number is equal to a union if it is equal to any of its options.
75
76 comparison
77 A number is greater than a union if it is greater than all its
78 options.
79
80 A number is less than a union if it is less than all its options.
81
82 union intersection
83 An intersection ("&") with a union is commutted across all options.
84 In other words:
85
86 (a | b | c) & d ==yields==> ((a & d) | (b & d) | (c & d))
87
88 Options that have no intersection with the new element are dropped.
89 The intersection of a constant number and a union yields that
90 number, if the number was in the union's ranges and otherwise
91 yields nothing.
92
94 Who knows. Collapsing overlapping options, probably.
95
97 Ricardo Signes <cpan@semiotic.systems>
98
100 This software is copyright (c) 2004 by Ricardo Signes.
101
102 This is free software; you can redistribute it and/or modify it under
103 the same terms as the Perl 5 programming language system itself.
104
105
106
107perl v5.38.0 2023-07-21 Number::Tolerant::Union(3)