public static double remainder(double dividend,double divisor){
  if (USE_JDK_MATH) {
  }
  if (Double.isInfinite(divisor)) {
    if (Double.isInfinite(dividend)) {
      return Double.NaN;
    }
 else {
      return dividend;
    }
  }
  double value=dividend % divisor;
  if (Math.abs(value + value) > Math.abs(divisor)) {
    return value + ((value > 0.0) ? -Math.abs(divisor) : Math.abs(divisor));
  }
 else {
    return value;
  }
}

public static double remainder ( double dividend , double divisor ) { if ( USE_JDK_MATH ) { } if ( Double . isInfinite ( divisor ) ) { if ( Double . isInfinite ( dividend ) ) { return Double . NaN ; } else { return dividend ; } } double value = dividend % divisor ; if ( Math . abs ( value + value ) > Math . abs ( divisor ) ) { return value + ( ( value > 0.0 ) ? - Math . abs ( divisor ) : Math . abs ( divisor ) ) ; } else { return value ; } }
returns dividend - divisor * n , where n is the mathematical integer closest to dividend / divisor . if dividend / divisor is equally close to surrounding integers , we choose n to be the integer of smallest magnitude , which makes this treatment differ from math . ieeeremainder ( double , double ) , where n is chosen to be the even integer . note that the choice of n is not done considering the double approximation of dividend / divisor , because it could cause result to be outside [ - | divisor | / 2 , | divisor | / 2 ] range . the practical effect is that if multiple results would be possible , we always choose the result that is the closest to ( and has the same sign as ) the dividend . ex . : - for ( - 3 . 0 , 2 . 0 ) , this method returns - 1 . 0 , whereas math . ieeeremainder returns 1 . 0 . - for ( - 5 . 0 , 2 . 0 ) , both this method and math . ieeeremainder return - 1 . 0 . if the remainder is zero , its sign is the same as the sign of the first argument . if either argument is nan , or the first argument is infinite , or the second argument is positive zero or negative zero , then the result is nan . if the first argument is finite and the second argument is infinite , then the result is the same as the first argument . nb : - modulo operator ( % ) returns a value in ] - | divisor | , | divisor | [ , which sign is the same as dividend . - as for modulo operator , the sign of the divisor has no effect on the result .
