Java Math.copySign(float magnitude, float sign)

Syntax

Math.copySign(float magnitude, float sign) has the following syntax.

public static float copySign(float magnitude,  float sign)

Example

In the following code shows how to use Math.copySign(float magnitude, float sign) method.


/*from   w w w.  j ava2 s .  co  m*/

public class Main {

   public static void main(String[] args) {

      float x = 123.4f;
      float y = -0.1234F;

      System.out.println(Math.copySign(x, y));
      System.out.println(Math.copySign(y, x));

   }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable