- TYPES OF INEQUALITY
- COPYRIGHT & LICENSE
Math::Inequalities::Parser - Minimum and maximum values allowed by an inequality.
use Math::Inequalities::Parser; my ($min, $max) = parse_inequality( ' 10 < n < 20 ' ); # $min = 11 # $max = 19
Tiny library for parsing integer maximum and minimum out when given an arbitrary inequality.
Because getting this simple thing right was far harder than it looked, and I never want to have to think about it again.
Parses an inequality string and returns a list of two values, the minimum and the maxium value that string will allow.
The simplest type, a single value, e.g.
42 = Min 42, Max 42.
Maximum is VALUE - 1, Minimum is undefined, e.g.
n < 42 = Min undef, Max 41.
Minimum is VALUE +1, Maximum is undefined, e.g.
n > 42 = Min 43, Max undef.
Maximum is VALUE, Minimum is undefined, e.g.
n < 42 = Min undef, Max 42.
Minimum is VALUE, Maximum is undefined, e.g.
n > 42 = Min 42, Max undef.
Handled as above, but with minimum and maximum reversed as expected.
Minimum is VALUE1 + 1, maximum is VALUE2 - 1, e.g
42 < n < 200 = Min 43, Max 199.
- Does not handle
VALUE1 <= n <= VALUE2or similar. Patches welcome.
- Does not complain at impossible
<VALUE1 < n < VALUE 2> combinations (e.g.
5 < n < 4) which result in a higher minumum than the maxiumum. Patches welcome.
- Does not work with negative numbers. Patches welcome.
- Always uses
nas the number identifier, this should be configureable at import time.
- Uses Exporter (should use Sub::Exporter)
- DOES NOT work with floating point numbers. I consider this a feature.
Tomas Doran (t0m)
Copyright 2011 the above author(s).
This sofware is free software, and is licensed under the same terms as perl itself.