public static double copySign(final double magnitude,final double sign){
  return Double.longBitsToDouble(Double.doubleToRawLongBits(sign) & Long.MIN_VALUE | Double.doubleToRawLongBits(magnitude) & Long.MAX_VALUE);
}

public static double copySign ( final double magnitude , final double sign ) { return Double . longBitsToDouble ( Double . doubleToRawLongBits ( sign ) & Long . MIN_VALUE | Double . doubleToRawLongBits ( magnitude ) & Long . MAX_VALUE ) ; }
a sign of nan can be interpreted as positive or negative .
