From: André Hentschel <nerv@da...>  20140620 19:26:07

BEGIN PGP SIGNED MESSAGE Hash: SHA1 Am 19.06.2014 22:36, schrieb Pavel: > Hi André, Hi, wow, thanks for having such a close look. > I have some comments to the sinf implementation. First of all, > calculating the factorials in separate function is quite inefficient, > since you repeat multiplication of what has already been multiplied. yeah, i guess that's even true when making it inline... > Slightly better would be to declare local variable and calculate the > factorial in the for loop: > > float fact = 1; > float y = 1; > float res = y; > for(int i = 1; i < 6; i++) > { > y *= x; > fact *= i; > res += y/fact; > } i think this could make the code more unreadable > this is rather an example for exp function, sine would require a > modification. And since you only calculate 6 values, it would be even > better to precalculate them and hardcode them in a table. yes, that's my best bet i guess, too. > However, calculating goniometric functions from Taylor expansion is > quite inefficient and slow in general. In your algorithm, you use 6 > values and power of 11, which itself introduces some error. The accuracy > of your implementation is 4 decimal digits at pi/2, where I believe the > deviation is the highest. > > I suggest the following formula for calculating sine at (0, pi/2) > interval: > > sin(x) = (0.99996736*x  0.09779183*x^2  0.12839086*x^3 + > 0.01826627*x^4) / (1  0.09809942*x + 0.03936879*x^2) > > This is accurate at 6 decimal digits in the whole interval, moreover it > matches the values at 0, pi/12, pi/6, pi/4, pi/3, 5*pi/12 and pi/2 > exactly. The highest deviation magnitude is about 7.8e7. I have derived > the coefficients using R. could you please attach some R code for this? My plan for now is to make those functions work, not spending too much time optimizing precision and performance. After that me and others could start improving both. So you can try with your formula later, hopefully also for other functions. > cosine can be then calculated as sin(pi/2  x) at the (0, pi/2) > interval. > > So I hope it might help you. It does, thanks! If you wanna continue looking into that, i put my code here: https://github.com/AndreRH/mingww64/commits/master Note that you sometimes get in trouble when fetching from it, as i might do forced pushes when needed. BEGIN PGP SIGNATURE Version: GnuPG v1 Comment: Using GnuPG with Thunderbird  http://www.enigmail.net/ iQGcBAEBAgAGBQJTpIrCAAoJEGm5GZTakYsseOML/3Lry/5hzegZBCC6LJAk397F qx8E59Y2lr6cSRgsp0HudkErh84+YALkb5tFxX24yHQwPs6sbxL9JClpReXJJNYH val9Vkj8lV0BiG2kSlPE1nPqqTUbHUbkCRc2mfylTzT1v2cLWNgkZhM+eUqtp1Xp j0tsyBCR0L6LU5SOFaqbpgnMn4A2DO/fN3GyPwZDubQ04iZXw/6toCWiN8RzRr8/ 8BBHCdMtJghS9l8LoEjOTD/ffSy6Pz7CEre7iuFRZA+LUcfncrstaMebAjjkui9p BBgtBQUas9gl6GtovmdD1jwFUJZyr7pezqOQTq2dBI9jmartYPogqc/+t1DBnJdf qpYigBC2NFzqSnOMN2E6U7FVCuQIS+IIzMNVKcqiw22V1JJsUNKQL9jsWcHT6ahr fmeMkdJyFjIdPDKo6gT6/7Jw0UzxDeFhx9iUFM79ieF/cjdNFqv72hyVNoNSSNZQ +xGDU05ahsSiuwLenh99yHS9iR76VCbbyl5n/TBX9w== =h95E END PGP SIGNATURE 