在最低和最高限值可能无效的情况下,Im 寻求一种简单的盘点浮标方式。
该法典是:
tval = float(-b - discriminant) / float (2*a)
if tval >= tmin and tval <= tmax:
return tval
tval = float(-b + discriminant) / float (2*a)
if tval >= tmin and tval <= tmax:
return tval
# Neither solution was within the acceptable range.
return None
然而,这完全不能处理无母体或最高权的情况(这应理解为没有最低或最高标准)。
迄今为止,我最能前来的就是:
tval = float(-b - discriminant) / float (2*a)
if (tmin == None or tval >= tmin) and (tmax == None or tval <= tmax):
return tval
tval = float(-b + discriminant) / float (2*a)
if (tmin == None or tval >= tmin) and (tmax == None or tval <= tmax):
return tval
# Neither solution was within the acceptable range.
return None
我始终认为,必须找到更好的(更清晰、更可读)方式来写。 任何想法?