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.
42 = Min 42, Max 42
Maximum is VALUE - 1, Minimum is undefined, e.g. n < 42 = Min undef, Max 41.
n < 42 = Min undef, Max 41
Minimum is VALUE +1, Maximum is undefined, e.g. n > 42 = Min 43, Max undef.
n > 42 = Min 43, Max undef
Maximum is VALUE, Minimum is undefined, e.g. n < 42 = Min undef, Max 42.
n < 42 = Min undef, Max 42
Minimum is VALUE, Maximum is undefined, e.g. n > 42 = Min 42, Max undef.
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.
42 < n < 200 = Min 43, Max 199
VALUE1 <= n <= VALUE2
<VALUE1 < n < VALUE 2
5 < n < 4
n
Tomas Doran (t0m) <bobtfish@bobtfish.net>
<bobtfish@bobtfish.net>
Dave Lambley
Copyright 2011 the above author(s).
This sofware is free software, and is licensed under the same terms as perl itself.
To install Math::Inequalities::Parser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::Inequalities::Parser
CPAN shell
perl -MCPAN -e shell install Math::Inequalities::Parser
For more information on module installation, please visit the detailed CPAN module installation guide.