Exemplo n.º 1
0
VectorD2 sincos(double x) {
	f64 sin_sign = 1.0, cos_sign = 1.0;

	if (x < 0.0) {
		x = -x;
		sin_sign = -1.0;
	}

	int j = int(x * M4PI);
	f64 y = j;

	if (j & 1) {
		++j;
		y += 1.0;
	}

	j &= 7;
	if (j > 3) { // reflect in x axis
		j -= 4;
		sin_sign = -sin_sign;
		cos_sign = -cos_sign;
	}

	if (j > 1) {
		cos_sign = -cos_sign;
	}
	
	f64 z = ((x - y*PI4A) - y*PI4B) - y*PI4C; // Extended precision modular arithmetic
	f64 zz = z * z;
	f64 cos = 1.0 - 0.5*zz + zz*zz*((((((costab[0]*zz)+costab[1])*zz+costab[2])*zz+costab[3])*zz+costab[4])*zz+costab[5]);
	f64 sin = z + z*zz*((((((sintab[0]*zz)+sintab[1])*zz+sintab[2])*zz+sintab[3])*zz+sintab[4])*zz+sintab[5]);

	if (j == 1 || j == 2) {
		return VectorD2(sin * cos_sign, cos * sin_sign);
	} else {
		return VectorD2(cos * cos_sign, sin * sin_sign);
	}
}
Exemplo n.º 2
0
 VectorD2 operator+(const VectorD2 vec) const {
     return VectorD2(x+vec.x,y+vec.y);
 }