2

Im trying to code a formula to calculate a theoretical delay on a ethernet network over 2000 users. I've some static declared variables, but i'm having an OverflowError due to the operation values. Any idea to solve this? Any guidance will be appreciated.

enter image description here

tp =0.87*10**-7
ti = 0.819*10**-3
c = 2
tg = 96/(1*10**7)
x_2 = ti**2
Et , Bt, Ew= [], [], [] 
for i in range(0,2000):
  lambdaa = i*2
  ro = lambdaa*(ti/2)
  Ew = (lambdaa*(x_2)/4*(1-ro))
  Bt = (tp/2)*(sum([2**(i-1)]))
  Et = (tp + ti + Ew +(c*(ti+tg+2*tp))+ Bt )

Traceback:

---> 12   Bt = (tp/2)*(sum([2**(i-1)]))
     13   Et = (tp + ti + Ew + Bt +(c*(ti+tg+2*tp)))
     14 

OverflowError: int too large to convert to float
  • 1
    Does this answer your question? [OverflowError: long int too large to convert to float in python](https://stackoverflow.com/questions/16174399/overflowerror-long-int-too-large-to-convert-to-float-in-python) – xiaoyu2006 Oct 10 '21 at 05:36
  • How much precision do you need? – The Singularity Oct 10 '21 at 05:36
  • @Luke Theoretically at least, Et has to have values between `10^-4` or `10^-5` – BlackAndWhite Oct 10 '21 at 05:43
  • 1) `sum([2**(i-1)])` is equal to `2**(i-1)`, you didn't implement the summation right. In fact, that sum of powers of 2 can be simplified to `2**i - 1`. 2) The error happens when you multiply a `float` `tp/2` by a HUGE integer `2**(i-1)`. In the extreme case, you have `2**1999`. Python's `float` is a 64-bit value with 11 bits for an exponent of 2. Those 11 bits only go from −1022 to +1023. You would need to use a different data type capable of representing bigger numbers, or you would have to change how you represent the data. For example, `(2, 1999)` can represent `2**1999` with less data. – BatWannaBe Oct 10 '21 at 06:23

0 Answers0