Title: What software should I use to create exponential type functions? Post by: M Benesi on April 14, 2014, 05:10:10 PM I'm running into a problem implementing the exponential function Taylor series expansion of sin and cosine in fragmentarium. I've messed around with various forms, and think it has something to do with the low precision of the floats.
My ancient GPU won't handle doubles anyway, but I was wondering which software I should use to implement my own exponential function variant. Here is code (for a plain old exponential function expansion of sin and cosine- not the code that I want to implement) that SHOULD work in Fragmentarium, but doesn't for whatever reason: Code: vec2 special2(float an) Title: Re: What software should I use to create exponential type functions? Post by: Syntopia on April 14, 2014, 07:21:40 PM Here is code (for a plain old exponential function expansion of sin and cosine- not the code that I want to implement) that SHOULD work in Fragmentarium, but doesn't for whatever reason: You just forgot to specify the 'vec2' constructor. Change to the following and it works: Code: vec2 tot=vec2(1.0,an); Notice, that this approximation quickly breaks down for large arguments (here shown for n = 63), so you should constrain the argument to the primary branch using mod(...). (http://blog.hvidtfeldts.net/media/cos.png) I also timed this, because I was curious. For n=63, the series approximation is roughly 8x slower, but for n=13 (which just covers the primary branch), the speed difference is only about 50%. Title: Re: What software should I use to create exponential type functions? Post by: M Benesi on April 14, 2014, 11:31:22 PM Thanks- that was driving me nuts, although I ignored the type cast warnings.
I was already constraining it between -2 and 2 pi. Finish this reply later- I have been summoned. Title: Re: What software should I use to create exponential type functions? Post by: Roquen on April 15, 2014, 09:05:33 AM Truncated series expansions are terrible cost vs. accuracy even if you could work with Reals (except in very small distance from the approximation point)...so they're pretty useless in practice. What do you really want to approximate?
Title: Re: What software should I use to create exponential type functions? Post by: M Benesi on April 15, 2014, 10:29:16 PM Thanks again Syntopia. @Roquen- I wrote out a series that ends up adding all the later portions of the binomial series minus the first portions for a "special" type of sin/cosine variant (a and b are both imaginary). Anyway, I didn't notice (pretty obvious now) that it ends up as... cosine (a+b) - cosine (a) and sin (a+b) - sin (a) So, I actually don't need to do the series expansion now that I see the light... its nothing special, and doesn't result in anything great. |