Original Post
Hey guys,
I'm trying to remove what seems to be a bottle neck in my noise function. I have a call to Math.Cos() which calculates the cosine in double precision but also adds another function call and cast to float. I have seen simple methods of estimating the cosine function in the past (using a parabola I think) but I'm having trouble tracking them down.
Anyways, here is the function I wish to speed up, any help is appreciated:
// cosine interpolation between a and b by a factor of x
public float lerp(float a, float b, float x)
{
float ft = x * 3.1415927f;
float f = (1.0f - (float)Math.Cos(ft)) * 0.5f;
return a * (1.0f - f) + b * f;
}
I'm trying to remove what seems to be a bottle neck in my noise function. I have a call to Math.Cos() which calculates the cosine in double precision but also adds another function call and cast to float. I have seen simple methods of estimating the cosine function in the past (using a parabola I think) but I'm having trouble tracking them down.
Anyways, here is the function I wish to speed up, any help is appreciated:
// cosine interpolation between a and b by a factor of x
public float lerp(float a, float b, float x)
{
float ft = x * 3.1415927f;
float f = (1.0f - (float)Math.Cos(ft)) * 0.5f;
return a * (1.0f - f) + b * f;
}
