#include <complex.h>
#include <math.h>

double complex complex_approx_turn(double turn)
{
    const static double a = 8 * M_SQRT2 / 3 - 3;
    const static double b = 4 - 8 * M_SQRT2 / 3;

    double p = turn * (b * turn * turn + a);
    double q = p * p;
    double r = 1 + q;
    double c = (1 - q) / r, s = 2 * p / r;

    return (c * c - s * s) + I * (2 * c * s);
}

double complex complex_turn(double turn) { return cexp(I * M_PI * turn); }

void turn_update(double turn, double complex* result)
{
    *result = complex_turn(turn);
}

void approx_turn_update(double turn, double complex* result)
{
    *result = complex_approx_turn(turn);
}
