taschini / pyinterval

PyInterval — Interval arithmetic in Python
http://pyinterval.readthedocs.io
Other
83 stars 25 forks source link

Calculate length of interval #2

Open stathisgotsis opened 9 years ago

stathisgotsis commented 9 years ago

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.

taschini commented 9 years ago

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))
kenahoo commented 7 years ago

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

taschini commented 7 years ago

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

krassowski commented 6 years ago

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