pyinterval
pyinterval copied to clipboard
Calculate length of interval
Is there a way to calculate the "length" of an interval ? To give an example the length of interval([1.0, 2.0], [3.0, 5.0]) would be 3.0.
A method to return the measure of an interval would be actually quite useful and easy to implement, and I cannot remember at the moment why I did not add it to the API. I guess there must have been some corner cases I was not too sure about.
I think I'll add it soon. In the meanwhile you can use the following code
def measure(x):
from interval import fpu
return fpu.up(lambda: sum((c.sup - c.inf for c in x), 0))
Still planning to add this? It would be useful for me too.
I'll try to add it for release 1.3, but getting it right is trickier than it might seem at first.
Having length() method would be a great addition ;)