示例#1
0
文件: ir.py 项目: Piruzzolo/Mathics
 def _gen_Csch(self, args):
     # FIXME this approach is inaccurate
     # Csch[x] = 2 / (Exp[x] + Exp[-x])
     a = self.call_fp_intr('llvm.exp', args)
     negx = self.builder.fsub(real_type(0.0), args[0])
     b = self.call_fp_intr('llvm.exp', [negx])
     return self.builder.fdiv(real_type(2.0), self.builder.fsub(a, b))
示例#2
0
文件: ir.py 项目: Piruzzolo/Mathics
 def _gen_Cosh(self, args):
     # FIXME this approach is inaccurate
     # Cosh[x] = (Exp[x] + Exp[-x]) / 2
     a = self.call_fp_intr('llvm.exp', args)
     negx = self.builder.fsub(real_type(0.0), args[0])
     b = self.call_fp_intr('llvm.exp', [negx])
     c = self.builder.fadd(a, b)
     return self.builder.fmul(c, real_type(0.5))
示例#3
0
文件: ir.py 项目: Piruzzolo/Mathics
    def _gen_ir(self, expr):
        '''
        walks an expression tree and constructs the ir block
        '''
        if isinstance(expr, Symbol):
            try:
                arg = self.lookup_args[expr.get_name()]
            except KeyError:
                raise CompileError()
            return arg
        elif isinstance(expr, Integer):
            return int_type(expr.get_int_value())
        elif isinstance(expr, Real):
            return real_type(expr.round_to_float())
        elif not isinstance(expr, Expression):
            raise CompileError()

        head_name = expr.get_head_name()
        if head_name.startswith('System`'):
            head_name = head_name[7:]
            method = getattr(self, '_gen_' + head_name, None)
        else:
            method = None

        if method is None:
            raise CompileError()

        return method(expr)
示例#4
0
文件: ir.py 项目: funbobbie/Mathics
 def _gen_Coth(self, args):
     # FIXME this approach is inaccurate
     # Coth[x] = (Exp[x] + Exp[-x]) / (Exp[x] - Exp[-x])
     a = self.call_fp_intr('llvm.exp', args)
     negx = self.builder.fsub(real_type(0.0), args[0])
     b = self.call_fp_intr('llvm.exp', [negx])
     return self.builder.fdiv(self.builder.fadd(a, b),
                              self.builder.fsub(a, b))
示例#5
0
文件: ir.py 项目: Piruzzolo/Mathics
 def _gen_Csc(self, args):
     # FIXME this approach is inaccurate
     sinx = self.call_fp_intr('llvm.sin', args)
     return self.builder.fdiv(real_type(1.0), sinx)
示例#6
0
文件: ir.py 项目: Piruzzolo/Mathics
 def _gen_Sec(self, args):
     # FIXME this approach is inaccurate
     cosx = self.call_fp_intr('llvm.cos', args)
     return self.builder.fdiv(real_type(1.0), cosx)
示例#7
0
 def _gen_Csc(self, args):
     # FIXME this approach is inaccurate
     sinx = self.call_fp_intr('llvm.sin', args)
     return self.builder.fdiv(real_type(1.0), sinx)
示例#8
0
 def _gen_Sec(self, args):
     # FIXME this approach is inaccurate
     cosx = self.call_fp_intr('llvm.cos', args)
     return self.builder.fdiv(real_type(1.0), cosx)