'use strict';

// MODULES //

var cos = require( 'math-cos' );
var floor = require( 'math-floor' );
var sin = require( 'math-sin' );
var float64bits = require( 'math-float64-bits' );
var trunc = require( 'math-trunc' );
	

// CONSTANTS //

var PI = require( 'const-pi' );


// SINPI //

/**
* FUNCTION: sinPi( x )
*	Helper function for negative x.
*
* @param {Number} x - input value
* @returns {Number} function value
*/
function sinPi( x ) {
	var Two52 = 4503599627370496,
		Two53 = 9007199254740992,
		z;

	if ( x < 0.25 ) {
		return -sin( PI * x );
	}

	// argument reduction
	z = floor( x );
	var n;
	if ( z !== x ) { // inexact
		x = x % 2;
		n = trunc( x * 4 );
	} else {
		if ( x >= Two53 ) { // x must be even
			x = 0;
			n = 0;
		} else {
			if ( x < Two52 ) {
				z = x + Two52; // exact
			}
			n =  1 & float64bits( z );
			x = n;
			n <<= 2;
		}
	}
	switch ( n ) {
	case 0:
		x = sin( PI * x );
		break;
	case 1:
	case 2:
		x = cos( PI * (0.5 - x) );
		break;
	case 3:
	case 4:
		x = sin( PI * (1 - x) );
		break;
	case 5:
	case 6:
		x = -cos( PI * (x - 1.5) );
		break;
	default:
		x = sin( PI * (x - 2) );
	}
	return -x;
} // end FUNCTION sinPI()


// EXPORTS //

module.exports = sinPi;

@@ -265,16 +265,94 @@
 -pi' );%0A
+var TWO52 = 4503599627370496; // 2**52%0Avar TWO53 = 9007199254740992; // 2**53%0A
 %0A%0A// SIN
@@ -524,68 +524,11 @@
 var 
-Two52 = 4503599627370496,%0A%09%09Two53 = 9007199254740992,%0A%09%09
 z;%0A
-%0A
 %09if 
@@ -570,17 +570,16 @@
 x );%0A%09%7D%0A
-%0A
 %09// argu
@@ -705,18 +705,18 @@
 ( x %3E= T
-wo
+WO
 53 ) %7B /
@@ -776,18 +776,18 @@
  ( x %3C T
-wo
+WO
 52 ) %7B%0A%09
@@ -802,10 +802,10 @@
  + T
-wo
+WO
 52; 

Move constants to parent scope