def pythonast(self, args, tonative=False):
arg, = args
justlog = ast.Call(ast.Attribute(ast.Name("$math", ast.Load()), "log", ast.Load()), [arg], [], None, None)
if self.base == math.e:
if tonative:
return justlog
else:
return ast.IfExp(ast.Compare(arg, [ast.Gt()], [ast.Num(0)]), justlog, ast.Num(-inf))
else:
scaled = ast.BinOp(justlog, ast.Div(), ast.Num(math.log(self.base)))
if tonative:
return scaled
else:
return ast.IfExp(ast.Compare(arg, [ast.Gt()], [ast.Num(0)]), scaled, ast.Num(-inf))
评论列表
文章目录