static strictfp long heavyRemainderPiO2(final double angle,final boolean negateRem){
  int n, i, j, ih;
  double fw;
  final long lx=Double.doubleToRawLongBits(angle);
  final long exp=(lx >> 52 & 0x7FF) - (1023 + 23);
  double z=Double.longBitsToDouble(lx - (exp << 52));
  final double x0=(int)z;
  z=(z - x0) * TWO_POW_24;
  final double x1=(int)z;
  z=(z - x1) * TWO_POW_24;
  final double x2=(int)z;
  final int e0=(int)exp;
  final int nx=x2 == 0.0 ? x1 == 0.0 ? 1 : 2 : 3;
  double f0, f1, f2, f3, f4, f5, f6, f7;
  double q0, q1, q2, q3, q4, q5;
  int iq0, iq1, iq2, iq3, iq4, iq5;
  final int jk=4;
  final int jx=nx - 1;
  final int jv=Math.max(0,(e0 - 3) / 24);
  final int qZero=e0 - 24 * (jv + 1);
  j=jv - jx;
  if (jx == 0) {
    f6=0.0;
    f5=0.0;
    f4=j >= -4 ? TWO_OVER_PI_TAB[j + 4] : 0.0;
    f3=j >= -3 ? TWO_OVER_PI_TAB[j + 3] : 0.0;
    f2=j >= -2 ? TWO_OVER_PI_TAB[j + 2] : 0.0;
    f1=j >= -1 ? TWO_OVER_PI_TAB[j + 1] : 0.0;
    f0=j >= 0 ? TWO_OVER_PI_TAB[j] : 0.0;
    q0=x0 * f0;
    q1=x0 * f1;
    q2=x0 * f2;
    q3=x0 * f3;
    q4=x0 * f4;
  }
 else   if (jx == 1) {
    f6=0.0;
    f5=j >= -5 ? TWO_OVER_PI_TAB[j + 5] : 0.0;
    f4=j >= -4 ? TWO_OVER_PI_TAB[j + 4] : 0.0;
    f3=j >= -3 ? TWO_OVER_PI_TAB[j + 3] : 0.0;
    f2=j >= -2 ? TWO_OVER_PI_TAB[j + 2] : 0.0;
    f1=j >= -1 ? TWO_OVER_PI_TAB[j + 1] : 0.0;
    f0=j >= 0 ? TWO_OVER_PI_TAB[j] : 0.0;
    q0=x0 * f1 + x1 * f0;
    q1=x0 * f2 + x1 * f1;
    q2=x0 * f3 + x1 * f2;
    q3=x0 * f4 + x1 * f3;
    q4=x0 * f5 + x1 * f4;
  }
 else {
    f6=j >= -6 ? TWO_OVER_PI_TAB[j + 6] : 0.0;
    f5=j >= -5 ? TWO_OVER_PI_TAB[j + 5] : 0.0;
    f4=j >= -4 ? TWO_OVER_PI_TAB[j + 4] : 0.0;
    f3=j >= -3 ? TWO_OVER_PI_TAB[j + 3] : 0.0;
    f2=j >= -2 ? TWO_OVER_PI_TAB[j + 2] : 0.0;
    f1=j >= -1 ? TWO_OVER_PI_TAB[j + 1] : 0.0;
    f0=j >= 0 ? TWO_OVER_PI_TAB[j] : 0.0;
    q0=x0 * f2 + x1 * f1 + x2 * f0;
    q1=x0 * f3 + x1 * f2 + x2 * f1;
    q2=x0 * f4 + x1 * f3 + x2 * f2;
    q3=x0 * f5 + x1 * f4 + x2 * f3;
    q4=x0 * f6 + x1 * f5 + x2 * f4;
  }
  double twoPowQZero=twoPowNormal(qZero);
  int jz=jk;
  z=q4;
  fw=(int)(TWO_POW_N24 * z);
  iq0=(int)(z - TWO_POW_24 * fw);
  z=q3 + fw;
  fw=(int)(TWO_POW_N24 * z);
  iq1=(int)(z - TWO_POW_24 * fw);
  z=q2 + fw;
  fw=(int)(TWO_POW_N24 * z);
  iq2=(int)(z - TWO_POW_24 * fw);
  z=q1 + fw;
  fw=(int)(TWO_POW_N24 * z);
  iq3=(int)(z - TWO_POW_24 * fw);
  z=q0 + fw;
  iq4=0;
  iq5=0;
  z=z * twoPowQZero % 8.0;
  n=(int)z;
  z-=n;
  ih=0;
  if (qZero > 0) {
    i=iq3 >> 24 - qZero;
    n+=i;
    iq3-=i << 24 - qZero;
    ih=iq3 >> 23 - qZero;
  }
 else   if (qZero == 0) {
    ih=iq3 >> 23;
  }
 else   if (z >= 0.5) {
    ih=2;
  }
  if (ih > 0) {
    n+=1;
    int carry=1;
    if (iq0 != 0) {
      iq0=0x1000000 - iq0;
      iq1=0xFFFFFF - iq1;
      iq2=0xFFFFFF - iq2;
      iq3=0xFFFFFF - iq3;
    }
 else     if (iq1 != 0) {
      iq1=0x1000000 - iq1;
      iq2=0xFFFFFF - iq2;
      iq3=0xFFFFFF - iq3;
    }
 else     if (iq2 != 0) {
      iq2=0x1000000 - iq2;
      iq3=0xFFFFFF - iq3;
    }
 else     if (iq3 != 0) {
      iq3=0x1000000 - iq3;
    }
 else {
      carry=0;
    }
    if (qZero > 0) {
      if (qZero == 1) {
        iq3&=0x7FFFFF;
      }
 else       if (qZero == 2) {
        iq3&=0x3FFFFF;
      }
    }
    if (ih == 2) {
      z=1.0 - z;
      if (carry != 0) {
        z-=twoPowQZero;
      }
    }
  }
  if (z == 0.0) {
    if (iq3 == 0) {
      return jdkRemainderPiO2(angle,negateRem);
    }
    if (jx == 0) {
      f5=TWO_OVER_PI_TAB[jv + 5];
      q5=x0 * f5;
    }
 else     if (jx == 1) {
      f6=TWO_OVER_PI_TAB[jv + 5];
      q5=x0 * f6 + x1 * f5;
    }
 else {
      f7=TWO_OVER_PI_TAB[jv + 5];
      q5=x0 * f7 + x1 * f6 + x2 * f5;
    }
    jz++;
    z=q5;
    fw=(int)(TWO_POW_N24 * z);
    iq0=(int)(z - TWO_POW_24 * fw);
    z=q4 + fw;
    fw=(int)(TWO_POW_N24 * z);
    iq1=(int)(z - TWO_POW_24 * fw);
    z=q3 + fw;
    fw=(int)(TWO_POW_N24 * z);
    iq2=(int)(z - TWO_POW_24 * fw);
    z=q2 + fw;
    fw=(int)(TWO_POW_N24 * z);
    iq3=(int)(z - TWO_POW_24 * fw);
    z=q1 + fw;
    fw=(int)(TWO_POW_N24 * z);
    iq4=(int)(z - TWO_POW_24 * fw);
    z=q0 + fw;
    iq5=0;
    z=z * twoPowQZero % 8.0;
    n=(int)z;
    z-=n;
    ih=0;
    if (qZero > 0) {
      i=iq4 >> 24 - qZero;
      n+=i;
      iq4-=i << 24 - qZero;
      ih=iq4 >> 23 - qZero;
    }
 else     if (qZero == 0) {
      ih=iq4 >> 23;
    }
 else     if (z >= 0.5) {
      ih=2;
    }
    if (ih > 0) {
      n+=1;
      int carry=1;
      if (iq0 != 0) {
        iq0=0x1000000 - iq0;
        iq1=0xFFFFFF - iq1;
        iq2=0xFFFFFF - iq2;
        iq3=0xFFFFFF - iq3;
        iq4=0xFFFFFF - iq4;
      }
 else       if (iq1 != 0) {
        iq1=0x1000000 - iq1;
        iq2=0xFFFFFF - iq2;
        iq3=0xFFFFFF - iq3;
        iq4=0xFFFFFF - iq4;
      }
 else       if (iq2 != 0) {
        iq2=0x1000000 - iq2;
        iq3=0xFFFFFF - iq3;
        iq4=0xFFFFFF - iq4;
      }
 else       if (iq3 != 0) {
        iq3=0x1000000 - iq3;
        iq4=0xFFFFFF - iq4;
      }
 else       if (iq4 != 0) {
        iq4=0x1000000 - iq4;
      }
 else {
        carry=0;
      }
      if (qZero > 0) {
        if (qZero == 1) {
          iq4&=0x7FFFFF;
        }
 else         if (qZero == 2) {
          iq4&=0x3FFFFF;
        }
      }
      if (ih == 2) {
        z=1.0 - z;
        if (carry != 0) {
          z-=twoPowQZero;
        }
      }
    }
    if (z == 0.0) {
      if (iq4 == 0) {
        return jdkRemainderPiO2(angle,negateRem);
      }
      jz--;
      twoPowQZero*=TWO_POW_N24;
    }
 else {
    }
  }
 else {
  }
  if (z != 0.0) {
    z/=twoPowQZero;
    if (z >= TWO_POW_24) {
      fw=(int)(TWO_POW_N24 * z);
      if (jz == jk) {
        iq4=(int)(z - TWO_POW_24 * fw);
        jz++;
        twoPowQZero*=TWO_POW_24;
        iq5=(int)fw;
      }
 else {
        return jdkRemainderPiO2(angle,negateRem);
      }
    }
 else {
      if (jz == jk) {
        iq4=(int)z;
      }
 else {
        iq5=(int)z;
      }
    }
  }
  fw=twoPowQZero;
  if (jz == 5) {
    q5=fw * iq5;
    fw*=TWO_POW_N24;
  }
 else {
    q5=0.0;
  }
  q4=fw * iq4;
  fw*=TWO_POW_N24;
  q3=fw * iq3;
  fw*=TWO_POW_N24;
  q2=fw * iq2;
  fw*=TWO_POW_N24;
  q1=fw * iq1;
  fw*=TWO_POW_N24;
  q0=fw * iq0;
  fw=PIO2_TAB0 * q5;
  fw+=PIO2_TAB0 * q4 + PIO2_TAB1 * q5;
  fw+=PIO2_TAB0 * q3 + PIO2_TAB1 * q4 + PIO2_TAB2 * q5;
  fw+=PIO2_TAB0 * q2 + PIO2_TAB1 * q3 + PIO2_TAB2 * q4 + PIO2_TAB3 * q5;
  fw+=PIO2_TAB0 * q1 + PIO2_TAB1 * q2 + PIO2_TAB2 * q3 + PIO2_TAB3 * q4 + PIO2_TAB4 * q5;
  fw+=PIO2_TAB0 * q0 + PIO2_TAB1 * q1 + PIO2_TAB2 * q2 + PIO2_TAB3 * q3 + PIO2_TAB4 * q4 + PIO2_TAB5 * q5;
  if (ih != 0 ^ negateRem) {
    fw=-fw;
  }
  return encodeRemainderAndQuadrant(fw,n & 3);
}

static strictfp long heavyRemainderPiO2 ( final double angle , final boolean negateRem ) { int n , i , j , ih ; double fw ; final long lx = Double . doubleToRawLongBits ( angle ) ; final long exp = ( lx > > 52 & 0x7FF ) - ( 1023 + 23 ) ; double z = Double . longBitsToDouble ( lx - ( exp << 52 ) ) ; final double x0 = ( int ) z ; z = ( z - x0 ) * TWO_POW_24 ; final double x1 = ( int ) z ; z = ( z - x1 ) * TWO_POW_24 ; final double x2 = ( int ) z ; final int e0 = ( int ) exp ; final int nx = x2 == 0.0 ? x1 == 0.0 ? 1 : 2 : 3 ; double f0 , f1 , f2 , f3 , f4 , f5 , f6 , f7 ; double q0 , q1 , q2 , q3 , q4 , q5 ; int iq0 , iq1 , iq2 , iq3 , iq4 , iq5 ; final int jk = 4 ; final int jx = nx - 1 ; final int jv = Math . max ( 0 , ( e0 - 3 ) / 24 ) ; final int qZero = e0 - 24 * ( jv + 1 ) ; j = jv - jx ; if ( jx == 0 ) { f6 = 0.0 ; f5 = 0.0 ; f4 = j >= - 4 ? TWO_OVER_PI_TAB [ j + 4 ] : 0.0 ; f3 = j >= - 3 ? TWO_OVER_PI_TAB [ j + 3 ] : 0.0 ; f2 = j >= - 2 ? TWO_OVER_PI_TAB [ j + 2 ] : 0.0 ; f1 = j >= - 1 ? TWO_OVER_PI_TAB [ j + 1 ] : 0.0 ; f0 = j >= 0 ? TWO_OVER_PI_TAB [ j ] : 0.0 ; q0 = x0 * f0 ; q1 = x0 * f1 ; q2 = x0 * f2 ; q3 = x0 * f3 ; q4 = x0 * f4 ; } else if ( jx == 1 ) { f6 = 0.0 ; f5 = j >= - 5 ? TWO_OVER_PI_TAB [ j + 5 ] : 0.0 ; f4 = j >= - 4 ? TWO_OVER_PI_TAB [ j + 4 ] : 0.0 ; f3 = j >= - 3 ? TWO_OVER_PI_TAB [ j + 3 ] : 0.0 ; f2 = j >= - 2 ? TWO_OVER_PI_TAB [ j + 2 ] : 0.0 ; f1 = j >= - 1 ? TWO_OVER_PI_TAB [ j + 1 ] : 0.0 ; f0 = j >= 0 ? TWO_OVER_PI_TAB [ j ] : 0.0 ; q0 = x0 * f1 + x1 * f0 ; q1 = x0 * f2 + x1 * f1 ; q2 = x0 * f3 + x1 * f2 ; q3 = x0 * f4 + x1 * f3 ; q4 = x0 * f5 + x1 * f4 ; } else { f6 = j >= - 6 ? TWO_OVER_PI_TAB [ j + 6 ] : 0.0 ; f5 = j >= - 5 ? TWO_OVER_PI_TAB [ j + 5 ] : 0.0 ; f4 = j >= - 4 ? TWO_OVER_PI_TAB [ j + 4 ] : 0.0 ; f3 = j >= - 3 ? TWO_OVER_PI_TAB [ j + 3 ] : 0.0 ; f2 = j >= - 2 ? TWO_OVER_PI_TAB [ j + 2 ] : 0.0 ; f1 = j >= - 1 ? TWO_OVER_PI_TAB [ j + 1 ] : 0.0 ; f0 = j >= 0 ? TWO_OVER_PI_TAB [ j ] : 0.0 ; q0 = x0 * f2 + x1 * f1 + x2 * f0 ; q1 = x0 * f3 + x1 * f2 + x2 * f1 ; q2 = x0 * f4 + x1 * f3 + x2 * f2 ; q3 = x0 * f5 + x1 * f4 + x2 * f3 ; q4 = x0 * f6 + x1 * f5 + x2 * f4 ; } double twoPowQZero = twoPowNormal ( qZero ) ; int jz = jk ; z = q4 ; fw = ( int ) ( TWO_POW_N24 * z ) ; iq0 = ( int ) ( z - TWO_POW_24 * fw ) ; z = q3 + fw ; fw = ( int ) ( TWO_POW_N24 * z ) ; iq1 = ( int ) ( z - TWO_POW_24 * fw ) ; z = q2 + fw ; fw = ( int ) ( TWO_POW_N24 * z ) ; iq2 = ( int ) ( z - TWO_POW_24 * fw ) ; z = q1 + fw ; fw = ( int ) ( TWO_POW_N24 * z ) ; iq3 = ( int ) ( z - TWO_POW_24 * fw ) ; z = q0 + fw ; iq4 = 0 ; iq5 = 0 ; z = z * twoPowQZero % 8.0 ; n = ( int ) z ; z -= n ; ih = 0 ; if ( qZero > 0 ) { i = iq3 > > 24 - qZero ; n += i ; iq3 -= i << 24 - qZero ; ih = iq3 > > 23 - qZero ; } else if ( qZero == 0 ) { ih = iq3 > > 23 ; } else if ( z >= 0.5 ) { ih = 2 ; } if ( ih > 0 ) { n += 1 ; int carry = 1 ; if ( iq0 != 0 ) { iq0 = 0x1000000 - iq0 ; iq1 = 0xFFFFFF - iq1 ; iq2 = 0xFFFFFF - iq2 ; iq3 = 0xFFFFFF - iq3 ; } else if ( iq1 != 0 ) { iq1 = 0x1000000 - iq1 ; iq2 = 0xFFFFFF - iq2 ; iq3 = 0xFFFFFF - iq3 ; } else if ( iq2 != 0 ) { iq2 = 0x1000000 - iq2 ; iq3 = 0xFFFFFF - iq3 ; } else if ( iq3 != 0 ) { iq3 = 0x1000000 - iq3 ; } else { carry = 0 ; } if ( qZero > 0 ) { if ( qZero == 1 ) { iq3 &= 0x7FFFFF ; } else if ( qZero == 2 ) { iq3 &= 0x3FFFFF ; } } if ( ih == 2 ) { z = 1.0 - z ; if ( carry != 0 ) { z -= twoPowQZero ; } } } if ( z == 0.0 ) { if ( iq3 == 0 ) { return jdkRemainderPiO2 ( angle , negateRem ) ; } if ( jx == 0 ) { f5 = TWO_OVER_PI_TAB [ jv + 5 ] ; q5 = x0 * f5 ; } else if ( jx == 1 ) { f6 = TWO_OVER_PI_TAB [ jv + 5 ] ; q5 = x0 * f6 + x1 * f5 ; } else { f7 = TWO_OVER_PI_TAB [ jv + 5 ] ; q5 = x0 * f7 + x1 * f6 + x2 * f5 ; } jz ++ ; z = q5 ; fw = ( int ) ( TWO_POW_N24 * z ) ; iq0 = ( int ) ( z - TWO_POW_24 * fw ) ; z = q4 + fw ; fw = ( int ) ( TWO_POW_N24 * z ) ; iq1 = ( int ) ( z - TWO_POW_24 * fw ) ; z = q3 + fw ; fw = ( int ) ( TWO_POW_N24 * z ) ; iq2 = ( int ) ( z - TWO_POW_24 * fw ) ; z = q2 + fw ; fw = ( int ) ( TWO_POW_N24 * z ) ; iq3 = ( int ) ( z - TWO_POW_24 * fw ) ; z = q1 + fw ; fw = ( int ) ( TWO_POW_N24 * z ) ; iq4 = ( int ) ( z - TWO_POW_24 * fw ) ; z = q0 + fw ; iq5 = 0 ; z = z * twoPowQZero % 8.0 ; n = ( int ) z ; z -= n ; ih = 0 ; if ( qZero > 0 ) { i = iq4 > > 24 - qZero ; n += i ; iq4 -= i << 24 - qZero ; ih = iq4 > > 23 - qZero ; } else if ( qZero == 0 ) { ih = iq4 > > 23 ; } else if ( z >= 0.5 ) { ih = 2 ; } if ( ih > 0 ) { n += 1 ; int carry = 1 ; if ( iq0 != 0 ) { iq0 = 0x1000000 - iq0 ; iq1 = 0xFFFFFF - iq1 ; iq2 = 0xFFFFFF - iq2 ; iq3 = 0xFFFFFF - iq3 ; iq4 = 0xFFFFFF - iq4 ; } else if ( iq1 != 0 ) { iq1 = 0x1000000 - iq1 ; iq2 = 0xFFFFFF - iq2 ; iq3 = 0xFFFFFF - iq3 ; iq4 = 0xFFFFFF - iq4 ; } else if ( iq2 != 0 ) { iq2 = 0x1000000 - iq2 ; iq3 = 0xFFFFFF - iq3 ; iq4 = 0xFFFFFF - iq4 ; } else if ( iq3 != 0 ) { iq3 = 0x1000000 - iq3 ; iq4 = 0xFFFFFF - iq4 ; } else if ( iq4 != 0 ) { iq4 = 0x1000000 - iq4 ; } else { carry = 0 ; } if ( qZero > 0 ) { if ( qZero == 1 ) { iq4 &= 0x7FFFFF ; } else if ( qZero == 2 ) { iq4 &= 0x3FFFFF ; } } if ( ih == 2 ) { z = 1.0 - z ; if ( carry != 0 ) { z -= twoPowQZero ; } } } if ( z == 0.0 ) { if ( iq4 == 0 ) { return jdkRemainderPiO2 ( angle , negateRem ) ; } jz -- ; twoPowQZero *= TWO_POW_N24 ; } else { } } else { } if ( z != 0.0 ) { z /= twoPowQZero ; if ( z >= TWO_POW_24 ) { fw = ( int ) ( TWO_POW_N24 * z ) ; if ( jz == jk ) { iq4 = ( int ) ( z - TWO_POW_24 * fw ) ; jz ++ ; twoPowQZero *= TWO_POW_24 ; iq5 = ( int ) fw ; } else { return jdkRemainderPiO2 ( angle , negateRem ) ; } } else { if ( jz == jk ) { iq4 = ( int ) z ; } else { iq5 = ( int ) z ; } } } fw = twoPowQZero ; if ( jz == 5 ) { q5 = fw * iq5 ; fw *= TWO_POW_N24 ; } else { q5 = 0.0 ; } q4 = fw * iq4 ; fw *= TWO_POW_N24 ; q3 = fw * iq3 ; fw *= TWO_POW_N24 ; q2 = fw * iq2 ; fw *= TWO_POW_N24 ; q1 = fw * iq1 ; fw *= TWO_POW_N24 ; q0 = fw * iq0 ; fw = PIO2_TAB0 * q5 ; fw += PIO2_TAB0 * q4 + PIO2_TAB1 * q5 ; fw += PIO2_TAB0 * q3 + PIO2_TAB1 * q4 + PIO2_TAB2 * q5 ; fw += PIO2_TAB0 * q2 + PIO2_TAB1 * q3 + PIO2_TAB2 * q4 + PIO2_TAB3 * q5 ; fw += PIO2_TAB0 * q1 + PIO2_TAB1 * q2 + PIO2_TAB2 * q3 + PIO2_TAB3 * q4 + PIO2_TAB4 * q5 ; fw += PIO2_TAB0 * q0 + PIO2_TAB1 * q1 + PIO2_TAB2 * q2 + PIO2_TAB3 * q3 + PIO2_TAB4 * q4 + PIO2_TAB5 * q5 ; if ( ih != 0 ^ negateRem ) { fw = - fw ; } return encodeRemainderAndQuadrant ( fw , n & 3 ) ; }
remainder using an accurate definition of pi . derived from a fdlibm treatment called __kernel_rem_pio2 . not defining a non - strictfp version for fastmath , to avoid duplicating its long and messy code , and because it ' s slow anyway , and should be rarely used when speed matters .
