Jam/tools.py

23 lines
451 B
Python
Raw Normal View History

2021-09-28 19:23:06 +00:00
# sign function
def sgn(x):
if x>=0:
return 1
return -1
2021-09-29 03:36:07 +00:00
# check whether a number is an integer (with tolerance)
def isint_nonzero(x):
if abs(x)<1e-11:
return False
return abs(round(x)-x)<1e-11
2021-11-24 22:18:27 +00:00
# check that a number is in an interval
def in_interval(x,a,b):
return x>=a and x<=b
2021-11-25 03:22:19 +00:00
# remove x from list a
def remove_fromlist(a,x):
if x in a:
a[a.index(x)]=a[len(a)-1]
a=a[:len(a)-1]
return a