so int has no infinity. i guess i just need to use some extremely large numbers. for this its going to need to be so large that repeating divide by some int not larger than 2**64 remains above 2**64 for a long time (no definition). such a number is going to take a lot of memory. that's why i was hoping that int supported an infinity.
infint = (2**64)**(2**32) # i doubt it will figure this out in 16GB
the real problem is the
time it takes to create the value for
infint. it's going to take as much
time as what the divides would, or close to it.
Why do you need an infinite int?
Just tidbit of useless knowledge:
>>> help(list.index)
Help on method_descriptor:
index(self, value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
(END)
So 9223372036854775807 is maximum index of list and pretty big int

>>> bin(9223372036854775807)
'0b111111111111111111111111111111111111111111111111111111111111111'
Error:
OverflowError: cannot convert float infinity to integer
Hm, the shortcut didn't work :-D
(Apr-17-2019, 04:37 PM)Gribouillis Wrote: [ -> ]Why do you need an infinite int?
i had a case where a network request was being done N time (or quit upon success) in a function, where N was previously set by another function call (could have passed along in the request call). then in another situation i wanted it to be an "infinite" number of tries. of course a very large int would accomplish the task. but i was hoping for there to be a way to meaningfully express that in the code. so i ended up coding:
infinity = 2**60 # close enough
client.set_retries(infinity)
the implementation of a dynamically extended int could have easily included an infinity and negative infinity. an implement i once wrote in S/370 assembler did support positive and negative infinity, with most arithmetic results with infinity giving infinity (divide by infinity being a notable exception). Python has math.inf that works the same way (but int() doesn't like it).
i suppose i could have used the float value there since all that is involved is subtract by 1 and testing for less than 1. but an int infinity would have made simpler code exactly descriptive of my intent.
now i'm wanting
range() to support float, Decimal, and even complex. just being mad crazy, again.
i suppose i should include bool in that list.
You're doing it wrong. Use Sentinel-Objects instead of numbers.
Example: Your function can return 0, -1, positive Integers and None
If you want to check for this return values, your code is getting complex.
Some example code with socket and sentinels:
import time
import socket
import errno
TIMEOUT = object()
BLOCKED = object()
NOROUTE = object()
def time_connect(ip, port):
with socket.socket() as sock:
sock.settimeout(10)
start = time.time()
try:
sock.connect((ip, port))
except socket.timeout:
return TIMEOUT
except ConnectionRefusedError:
return BLOCKED
except OSError as e:
if e.errno == errno.EHOSTUNREACH:
return NOROUTE
else:
# raise the OSError
# if it's another error than
# EHOSTUNREACH
raise
stop = time.time()
return stop - start
def caller():
result = time_connect('127.0.0.1', 66)
if result is TIMEOUT:
print('Got a timeout')
elif result is BLOCKED:
print('Port is closed')
elif result is NOROUTE:
print('No route to ip')
else:
print('It took', result, 'to connect to the port')
caller()
https://python-patterns.guide/python/sentinel-object/
https://pythonbytes.fm/episodes/show/124...ooking-for
https://treyhunner.com/2019/03/unique-an...in-python/
PS: This will not work, if you're using multiprocessing. In this case the objects are still there, but they have a different memory address. It's a different object as in the main process for example. If you use threading, this is supported, because of shared memory. To reach the same approach with multiprocessing seems difficult for me. You can't overload the
is
keyword with magic methods.
Use for float-range
np.linspace
.
You can't get it faster, it's implemented in c.
Having this kind of god-functions, which can handle all possible cases, are too often overcomplicated and wrong.
You never can handle all possible cases in a logical way. This makes the use of the god-function harder.
(Apr-17-2019, 07:30 PM)perfringo Wrote: [ -> ]Just tidbit of useless knowledge:
>>> help(list.index)
Help on method_descriptor:
index(self, value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
(END)
So 9223372036854775807 is maximum index of list and pretty big int 
is 2**63-1
now that we have reached the age of 64-bit CPUs being common, issues like integers calculating huge amounts of money like nation-wide amounts, are mostly gone.
the number of times Donald Trump lies each day is still an issue, even in Python and Pike.