suri <hs***@usc.ed u> wrote in message
news:c7******** ****@ID-233334.news.uni-berlin.de...
I downloaded glibc and tried looking for the code that implements the
sine function
i couldnt find the file.
i went to the math directory and found math.h.. i guess that needs to be
included for the sine function. but which .c file implements the
sine/cosine and other trig fns
Here is one way, but not the most advanced way. It is fairly suitable for a
float (precision wise) but not for a double.
#include <iostream.h>
#include <iomanip.h>
#include <math.h>
// Source AMS 55, eqn 4.3.97. Handbook of Mathematical Functions, Pub by
U.S. Dept of Commerce
float sinx(float x)
{
static const float a[] =
{-.1666666664,.00 83333315,-.0001984090,.00 00027526,-.0000000239};
float xsq = x*x;
float temp = x*(1 + a[0]*xsq + a[1]*xsq*xsq + a[2]* xsq*xsq*xsq
+a[3]*xsq*xsq*xsq*xs q
+ a[4]*xsq*xsq*xsq*xs q*xsq);
return temp;
}
// ------------------
void test()
{
float x;
while(1)
{
cin >> x;
if(x<0. || x > (3.1416/2) )
{
cout << "Argument to sinx must be in range 0>= x <= pi/2 \n";
continue;
}
cout << sinx(x) << setw(12) << (float)sin(x) << endl;
}
The test code, but not the sinx() code, is in C++ which I suppose will lead
to some hissy fits since this is a C group. It is also a pre-standard
version of C++ so I suppose there will be some more hissy fits from that
quarter. So be it.