sinPi function
Implementation
double sinPi(double x) {
final double Two52 = 4.5036e+15; // 0x4330000000000000 ~4.5036e+15
final double Two53 = 9.0072e+15; // 0x4340000000000000 ~9.0072e+15
if (x < 0.25) {
return -math.sin(math.pi * x);
}
// argument reduction
double z = x.floorToDouble();
int n = 0;
if (z != x) {
// inexact
x = x.remainder(2);
n = (x * 4).toInt();
} else {
if (x >= Two53) {
// x must be even
x = 0.0;
n = 0;
} else {
if (x < Two52) {
z = x + Two52; // exact
}
n = Double.bit0(z);
x = n.toDouble();
n <<= 2;
}
}
switch (n) {
case 0:
x = math.sin(math.pi * x);
break;
case 1:
case 2:
x = math.cos(math.pi * (0.5 - x));
break;
case 3:
case 4:
x = math.sin(math.pi * (1 - x));
break;
case 5:
case 6:
x = -math.cos(math.pi * (x - 1.5));
break;
default:
x = math.sin(math.pi * (x - 2));
break;
}
return -x;
}