Rotate and translate a 2D point N times This is a C++ program that rotates a point initially located at origin by a given angle A (degree) counterclockwise and L translate its x-coordinate (sum L to it).

Here is my program:

Firstly it reads the number of test cases.
Each test case has 2 real numbers and 1 integer that represents a rotation, translation and how many times the operation of rotate and translate must be applied.

#include &lt;cstdio&gt;
#include &lt;utility&gt;
#include &lt;cmath&gt;


#define gc getchar_unlocked()
inline double getDouble() {
    double v;
    scanf("%lf",&amp;v);
    return v;
}

#define CONST 0.01745329251994329576922 //3.14159265358979323846/180 = 0.01745329251994329576922
std::pair&lt;double, double&gt; rotate(std::pair&lt;double, double&gt; p, double a){
    double rad = a*CONST;
    return std::make_pair(p.first*std::cos(rad) - p.second*std::sin(rad), p.first*std::sin(rad) + p.second*std::cos(rad));
}


int main(void){
    int t = (int) getDouble();

    for (int i = 0; i &lt; t; ++i) {
        double a = getDouble(),l = getDouble();
        int v = (int) getDouble();

        std::pair&lt;double, double&gt; p(0,0);
        while (v--) {
            p = rotate(p, a);
            p.first += l;
         }
        //for cases like 30 1.5 121... the printf just put -0.00
        if(std::abs(p.first) &lt; 0.005)
            p.first = 0;
        if(std::abs(p.second) &lt; 0.005)
            p.second = 0;
        printf("%.2lf %.2lf\n",p.first,p.second);
    }

    return 0;
}


Sample input:


  4
  90 10 1
  90 10 2
  90 10 3
  30 1.5 1000000000


Sample output:


  10.00 0.00
  10.00 10.00
  0.00 10.00
  3.55 3.55


How to make it faster ?
CONST is not a name; it doesn't convey any meaning. Call it something like rads_per_degree. If you feel you need to comment on the value, better do the calculation explicitly (take advantage of \$\pi\$ being defined for you in cmath):

const double rads_per_degree = M_PI / 180;

Each time you rotate, you recalculate radian measure, sin and cos. Within the test case these values do not change. You may safely precompute them:

double rads = rads_per_degree * angle;
double sin = std::sin(rads);
double cos = std::cos(rads);
while (v--) {
    do_math(x, y, sin, cos, L);
}

I am not sure why you special cased small values.
getDouble is somewhat dubious. It would've make sense to have such a function to sanitize input. As written, it is meaningless. Also, you should not read integer as double.