code: public static double copySign(double magnitude, double sign) {
          return Math.copySign(magnitude, (Double.isNaN(sign)?1.0d:sign));
      }
docs: Returns the first floating-point argument with the sign of the
  second floating-point argument.  For this method, a NaN
  {@code sign} argument is always treated as if it were
  positive.
  
  @param magnitude  the parameter providing the magnitude of the result
  @param sign   the parameter providing the sign of the result
  @return a value with the magnitude of {@code magnitude}
  and the sign of {@code sign}.
  @since 1.6