Finding Overlap in Ranged tuples

I have a pair of tuples (0,10) & (5, 15). I would like to write a function that will detect an overlap of numbers and return the numerical value of overlap(the amount of overlap). Is there an existing function to perform this comparison? I would like to use the quickest solution possible and avoid conditional statements...any ideas?
I needed this exact thing ages ago, I seem to recall that I eventually came up with:

max(0, min(e1,e2) - max(s1, s2))

where the first interval is (s1,e1) and the second is (s2,e2)

I'm not 100% sure that is right, so double check it.
max(0, min(e1,e2) - max(s1, s2) + 1)

Just need to add 1 since I assume (0, 10) & (10 , 15) should return an overlap of one number which is 10.
Topic archived. No new replies allowed.