new QSIN (QQSIN)

Previous topic - Next topic

kanonet

#30
After a long time a new version, everything got calculated new, from scratch. It offers higher precision than previous one and slightly more speed (up to +10% compared to last version).
Code (glbasic) Select
FUNCTION QQSIN: x // by Kanonet
IF x<360 AND x>-1
IF x>180
x = ( 1.523087104493429e-4 * x - 8.224670263788969e-2 ) * x + 11.10330492621077
RETURN ( ( 1.111111111111111e-2 * x - 1.666666666666667e-1 ) * x + 1 ) * x - 1
ENDIF
x = ( 1.523087104493429e-4 * x - 2.741556799711035e-2 ) * x + 1.233700559869966
RETURN ( ( 1.666666666666667e-1 - 1.111111111111111e-2 * x ) * x - 1 ) * x + 1
ENDIF

x=x*182.044444444444445
LOCAL xx%=bAND(x, 65535)
IF xx > 32767
x = ( 4.595892692064137e-9 * xx - 4.517946286638592e-4 ) * xx + 11.10330492621077
RETURN ( ( 1.111111111111111e-2 * x - 1.666666666666667e-1 ) * x + 1 ) * x - 1
ENDIF
x = ( 4.595892692064137e-9 * xx - 1.505982095546197e-4 ) * xx + 1.233700559869966
RETURN ( ( 1.666666666666667e-1 - 1.111111111111111e-2 * x ) * x - 1 ) * x + 1
ENDFUNCTION
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Wampus


Qedo

My version QQSIN2.
Perhaps not the most precise but faster, almost 50%.
I enclose an application of.
Ciao

FUNCTION QQSIN2: x  // by Qedo
LOCAL xx%
xx=x* 182.04166666666666666666666666667
xx=bAND(xx , 65535)
   IF xx < 32767
      x = ( 0.00012206791406720535999456453271949 - 0.0000000037255156354636406577669912201935 * xx)* xx
      RETURN ( 0.775 + 0.225 * x ) * x
   ENDIF
   xx= 32767 - xx
   x = ( 0.00012206791406720535999456453271949 + 0.0000000037255156354636406577669912201935 * xx) * xx
   RETURN ( 0.775 - 0.225 * x ) * x
ENDFUNCTION

[attachment deleted by admin]

fuzzy70

I must be doing something wrong or there is an incorrect setting somewhere as no matter what I do it is always 60fps  :blink:

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

kanonet

Fuzzy maybe its your hardware, or somthing? Runs with 560 fps my laptop.

Qedo, 180°=32768 not 32767
Yes my function was optimised for giving more accuracy at still good speed (on my machine its 7 times faster than original GLBasic SIN). If you want pure speed (and thats why we create this functions^^), than you need to stick with the old calculations (which are still based on Gernots QSIN). How did you do your calculations, starting with Gernots one again, or just adding to our last version? I did all calculations from Gernots base again (to avoid adding up inaccuracies) and added some extra speed improvements.
No finally QQSIN is 10 times faster than original GLBasic SIN!

Of cause more testing is always useful and we optimised it so much that most new optimisations arent necessarily useful on every machine. E.g. on my windows tablet with crappy AMD-C50 CPU, my accuracy functions outruns every other function by far, even Oceans c lookup table (which is pretty slow on that machine)! I have no idea why, cuz it shouldnt... (maybe its 32bit float vs 64bit float?)

Code (glbasic) Select
FUNCTION QQSIN: x   // by Kitty Hello, Qedo, Kanonet
LOCAL xx% = bAND( x * 182.04166666666666666666666666667 , 65535 )
IF xx < 32768
x = ( 5.790101276423631e-5 - 1.767113300842517e-9 * xx ) * xx
RETURN ( 1.633843488304938 + x ) * x
ENDIF
xx = 32768 - xx
x = ( 5.790101276423631e-5 + 1.767113300842517e-9 * xx ) * xx
RETURN ( 1.633843488304938 - x ) * x
ENDFUNCTION
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

fuzzy70

I found the culprit, in the driver settings if I change vertical sync from "Application Controlled" to "Forced off" it runs faster, must of changed after the last driver update as don't recall changing it myself.

DRAWRECT shows similar FPS in GLB Sin 211 fps & QQSin2 around 220 fps.

When I switch to Polyvectors, GLB sin 373 fps & QQSin 920 fps so around 2.4 times the speed up. The QQSin in your last post at 1010 fps so a slight speed up.

My machine specs are Core2Duo 2.13ghz, Nvidia 240GT & Win7 32bit

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

ketil

Quote from: kanonet on 2012-Mar-11

Of cause more testing is always useful and we optimised it so much that most new optimisations arent necessarily useful on every machine. E.g. on my windows tablet with crappy AMD-C50 CPU, my accuracy functions outruns every other function by far, even Oceans c lookup table (which is pretty slow on that machine)! I have no idea why, cuz it shouldnt... (maybe its 32bit float vs 64bit float?)


Seems a bit odd. Are the lookup-table packed to 32 or 64 bit integers (depending on os/processor) in the C code ?

#pragma pack(push)  /* current alignment to stack */
#pragma pack( integer_size )     /* set alignment to 32 or 64 bit integers depending on platform */

... C lookup-table here ...

#pragma pack(pop)

Correctly alligned tables are faster ....
"Sugar makes the world go 'round. Caffeine makes it spin faster."

Qedo


@kanonet
Code (glbasic) Select

How did you do your calculations, starting with Gernots one again, or just adding to our last version?

I started by Gernot  and your code and in detail i have substituted the original numeric value in this way:
// 65535 = (2^16)-1
// 182.04166666666666666666666666667 = 65535/360
// 0.00012206791406720535999456453271949 =   0.02222144652331750907567718514381/182.04166666666666666666666666667
// 0.000000003725515635463640657766991220193 = 0.00012346049003081125437778164739108/(182.04166666666666666666666666667^2)

And instead How did you do your calculations?
As you have deleted a multiplication?
Good
Ciao




kanonet

@Qedo:
Oups there you pointed me to an error in my code, it needs to be 65536/360 which is 182.044444444444444444...
So this is the code actually:
Code (glbasic) Select
FUNCTION QQSIN: x   // by Kitty Hello, Qedo, Kanonet
LOCAL xx% = bAND( x * 1.820444444444444e2 , 65535 )
IF xx < 32768
x = ( 5.790101276423631e-5 - 1.767113300842517e-9 * xx ) * xx
RETURN ( 1.633843488304938 + x ) * x
ENDIF
xx = 32768 - xx
x = ( 5.790101276423631e-5 + 1.767113300842517e-9 * xx ) * xx
RETURN ( 1.633843488304938 - x ) * x
ENDFUNCTION


To my calculations:
I went back to the original maths from Gernot and added my improvements. I did not add up to already transformed decimals, cuz this would lead into less precision, without winning speed. Here you see my full calculations (for x<180), including how i got rid of this multiplication:
Code (glbasic) Select
x = (1.2732 * (xx*360./65536./57.296) -0.4053 * (xx*360./65536./57.296) * (xx*360./65536./57.296) )*SQR(0.225)
RETURN (0.775/SQR(0.225) + x)*x


@Ketil:
i cant code C so i cant answer your question. Maybe youre right and something in his C code isnt perfect, cuz if i write my own lookuptable based sin function in glbasic its almost as fast as the C one on my main machine and way faster on my tablet, but still my QQSIN is the fastest one this machine (on my main machine the Oceans C one is the fastest - at least most of the times).
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Hemlos

Hmm more speed, i like this idea :)

Question though...what are the limitations for acceptable input value?

One more question...is this the fastest routine?

Code (glbasic) Select
FUNCTION QQSIN: x   // by Kitty Hello, Qedo, Kanonet
LOCAL xx% = bAND( x * 1.820444444444444e2 , 65535 )
IF xx < 32768
x = ( 5.790101276423631e-5 - 1.767113300842517e-9 * xx ) * xx
RETURN ( 1.633843488304938 + x ) * x
ENDIF
xx = 32768 - xx
x = ( 5.790101276423631e-5 + 1.767113300842517e-9 * xx ) * xx
RETURN ( 1.633843488304938 - x ) * x
ENDFUNCTION
Bing ChatGpt is pretty smart :O

kanonet

There are no known limitations, even very big positive or negative values are ok (as long as they dont cause a buffer overflow). But keep in mind, that it is not as accurate as the original GLB SIN function. So if you need to calculate very small changes or want to add up many sin values, you better stick with the original SIN.

If you like the faster sin function, you may also like my libQMATH which contains faster calculations for many math functions. see here: http://www.kanonet.de/downloads/libqmath
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Hemlos

thanks for the lib

why does atan have only one input and output in that lib, and glbasic has 2 in and out?
Bing ChatGpt is pretty smart :O

Hemlos

aisde from atan..

this is in qatan2 causing an error:

RETURN IIF( x>180, x-180, x )
Bing ChatGpt is pretty smart :O

kanonet

Yeah ATAN normally only has one parameter and not two. If you want two parameters, that use ATAN2. Its called this way in most languages, only GLBasic just offers ATAN2 but called it ATAN. I decided to include both, so you can use what you need.

About your error:
Im using V11 beta, and IIF is a new command V11. I used this command without thinking about users with V10, sorry. To use it with V10, just replace this line with this:
Code (glbasic) Select
IF x>180 THEN RETURN x-180
RETURN x

Or get new version from my website.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Hemlos

Hmm, how do i calculate this?

ATAN(X,Y)

Im using this in the PE btw..for missle guidance ;P
Bing ChatGpt is pretty smart :O