[SNIPPET][TRASH]Calculating sine.
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>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. |
Re: [SNIPPET][TRASH]Calculating sine.
you could have just found the taylor numbers for sine on the internet, also to extend it to [0,Pi] you could have just added an if(pi>ang>pi/2), then decrease the angle by pi then multiply the result by -1, you could have just as well extended it to -inf;+inf easily
|
Re: [SNIPPET][TRASH]Calculating sine.
yep. the taylor numbers are easy to calculate, and that wouldn't be as fun as trying something new. and, actually, if pi/2<ang<pi, i could just calculate sin(pi-ang). i, actually, did it and expanded it to -infinite ane +infinite, but when i compared it to the native sine function, it was slower, thus there would be no point in using a function that is slower and less accurate...
|
Re: [SNIPPET][TRASH]Calculating sine.
btw im pretty sure that the built-in sine function uses taylor numbers too just higher precision.
|
Re: [SNIPPET][TRASH]Calculating sine.
no, i didn't use taylor numbers. the built in sine has higher precision because it probably goes to the seventh derivative, creating a polynom of p7(a+bx+cx^2+...+hx^7). i just reached p4(a+bx+cx^2+dx^3+ex^4).
|
| All times are GMT -4. The time now is 18:30. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.