2) The constants are reals, which are rounded to a float and these errors compound over the polynomial evaluation. Numeric methods take into account FP usage.
hehe that's where double become your friend... and for an unknow reason you're forcing float WTF ? : 32 bit more precision are not negligeable in such computation, just try
NB: division is very slow in comparaison of multiplication/addition/substraction, using constant is not an option for evident speed reason
EDIT : Let me explain ....
static double f1= 1.0/120.0;
static double f2= 1.0/6.0;
public static double sin_r0d(double x)
{
double x2 = x*x;
return x * (1.0 + x2 * (x2 * f1 - f2));
}
public static double sin_r0d2(double x)
{
return x+Math.pow(x,5)/120.0-Math.pow(x,3)/6.0;
}
public static double sin_r0d3(double x)
{
double x2 = x*x;
return x * (1 + x2 * (x2 * (1.0/120.0) - (1.0/6.0)));
}
Output :
sin_n0(Math.PI*0.5)=0.9999977
sin_r0(Math.PI*0.5)=1.0045248
sin_r0d(Math.PI*0.5)=1.0045248555348174
sin_r0d2(Math.PI*0.5)=1.0045248555348174
sin_r0d3(Math.PI*0.5)=1.0045248555348174
error stay very low on all double computation and for your sample code all double computation results are identical and more accurate