Download the PHP package jstewmc/interval without Composer
On this page you can find all versions of the php package jstewmc/interval. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package interval
interval
A set of numbers between two endpoints.
Syntax
This library supports standard US interval syntax requiring (in order):
- an open-bracket (
[) or open-parentheses ((); - a number, positive infinity (
INF), or negative infinity (-INF); - a comma-space (
,); - a number, positive infinity (
INF), or negative infinity (-INF); and, - a close-bracket (
]) or close-parentheses ()).
Positive or negative floats, integers, and infinity are accepted.
For example:
(2, 4]represents 2 < x <= 4(-10.5, 10.5)represents -10.5 < x < 10.5[0, INF)represents 0 <= x < ∞(-INF, INF)represents -∞ < x < ∞
Keep in mind, this library does not support reverse-bracket syntax (e.g., ]2, 4]) or semi-colon separated syntax (e.g., [2; 4]).
Usage
You can instantiate an interval from a string or create it manually using the set methods:
Keep in mind, when instantiating an interval from a string, an InvalidArgumentException will be thrown if the interval's syntax is invalid:
Infinity is supported as the string 'INF' or the INF predefined constant:
You can compare a value to the interval using the compare() method. The compare() method will return -1, 0, or 1 if the value is below, inside, or above the interval, respectively:
You can get any of the interval's settings with the get methods:
There are a few convenience methods to make getting and setting the boundaries eaiser:
That's about it!
License
Author
Jack Clayton
Version
1.0.0, August 13, 2016
- Major release
- Update
composer.json
0.2.0, August 7, 2016
- Add support for infinity (e.g.,
'(-INF, 0]'). - Update error messages to be a little more informative.
- Update README examples.
0.1.0, August 6, 2016
- Initial release