Advertisement
Zastin

std.Expr with sin/cos (VS) #Bad idea#

Dec 4th, 2017
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. ALWAYS SLOWER THAN STD.LUT
  2. This should only really be used if you absolutely must use std.Expr
  3.  
  4. import math
  5. from functools import partial
  6.  
  7. def trig_expr(acc=7, func='sin'):
  8.     a = list(range(5, acc+1, 2))
  9.     f = [math.factorial(x) for x in a]
  10.     pm = {0: '+', 1: '-'}
  11.     ds = {False: 'dup1', True: 'swap'}
  12.     e = ' {} dup dup 3 pow 6 / - '.format('' if func=='sin' else ' {} 2 / + '.format(math.pi))
  13.     for i in range(acc//2 - 1):
  14.         e += ' {} {} pow {} / {} '.format(ds[i == acc//2 - 2], a[i], f[i], pm[i%2])
  15.     return e
  16.    
  17. sin, cos = [partial(trig_expr, func=f) for f in ('sin', 'cos')]
  18.  
  19. """
  20. expr = 'x sin'.replace('sin', sin(7) )
  21. core.std.Expr(clip32, expr)
  22. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement