Raised This Month: $ Target: $400
 0% 

[SNIPPET][TRASH]Calculating sine.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 09-16-2013 , 01:11   [SNIPPET][TRASH]Calculating sine.
Reply With Quote #1

well, this is probably the worst snippet you will ever read. it serves for almost nothing...
the function i made calculates sine for any angle at the interval [0;Pi/2] with a precision of 10^(-3)[i guess...]. i know, it's a horrible precision and it's very limited, however it calculates sine 7% to 10% faster than the native function for calculating sine.
anyway, it's trash.
well, if you need to calculate 100 million sines in a row of angles in [0;pi/2] with low precision, this is the right snippet for you:
Code:
#include <sourcemod>

#pragma semicolon 1

#define C0 0.00023301105055311040507405363895867744838057969783202801
#define C1 0.99544724482913058418216562176926738156431820708931287424
#define C2 0.02093370138860544581496859818026477588188983853689570814
#define C3 0.20386398831094746691085039624037738708809526005357954191
#define C4 0.02864641864877972104358109297731732858321869940620898045

stock Float:Mat_Sine(Float:ang){

	return C0+C1*ang+C2*(ang*ang)-C3*(ang*ang*ang)+C4*(ang*ang*ang*ang);

}
i learnt that taylor series are used to calculate sine. but, then, i wondered, what if i used linear algebra to do it, would it be faster? yes, it would, since you do a function that only works at a very limited interval.
actually, if i had used the same subspace that the taylor series for calculating sine uses, i would for sure have got a polynom that approximates the sine function better than the series in the whole interval of the series, which i guess it's [0, 2pi] or [-pi, pi], although it would take much more time to run than the series. however, i got tired at P4 subspace, i would never be able to get to P7(i can't handle 8 dimensions, that's too much! maybe i could make the computer handle it for me... well, it's meaningless) subspace, which i think it's the one used by the series...
this is the first draft that i made:
Spoiler

the other one keeps the same logic, except by the fact that it has integrals with sine.
__________________
sie sind das essen und wir sind die jäger!

Last edited by Bimbo1; 09-16-2013 at 01:20.
Bimbo1 is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:30.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode