pyinterval icon indicating copy to clipboard operation
pyinterval copied to clipboard

Calculate length of interval

Open stathisgotsis opened this issue 9 years ago • 4 comments

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.

stathisgotsis avatar Sep 12 '15 20:09 stathisgotsis

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))

taschini avatar Oct 14 '15 20:10 taschini

Still planning to add this? It would be useful for me too.

kenahoo avatar Mar 01 '17 23:03 kenahoo

I'll try to add it for release 1.3, but getting it right is trickier than it might seem at first.

taschini avatar Mar 05 '17 22:03 taschini

Having length() method would be a great addition ;)

krassowski avatar May 02 '18 09:05 krassowski