I am calling a function which computes and retu some value. The expression has two parts to it, as seen below:
def fSMHM(x, alpha, delta, gamma) :
#cst is some constant value
val = cst + delta*((np.log10(1+np.exp(x)))**gamma)/(1+np.exp(10**(-x)))
retu val
fSMHM(np.log10(Mh/m1), alpha, delta, gamma)
For x << 1, the denominator of the second term becomes extremely large (i.e, the term 1+np.exp(10**(-x))), and yields an overflow. I would like to handle cases that yield an overflow by simply retuing the first term. Is there a way to do this? I tried using a try-except like:
def fSMHM(x, alpha, delta, gamma) :
#cst is some constant value
try:
val = cst + delta*((np.log10(1+np.exp(x)))**gamma)/(1+np.exp(10**(-x)))
except:
val = cst
retu val
But this did not work... Instead, an overflow error was still raised. Thanks in advance :)
