StrictMath copySign() in Java
-
The copySign(float mvalue, float sign) is an inbuilt method of StrictMath class in Java which is used to get the first floating-point argument with the sign of the second floating-point argument. A NaN sign argument in this functin is considered as a positive.
Syntax :public static float copySign(float mvalue, float sign)
Parameters : This method accepts two parameters:
- mvalue: This is of float type which provides the magnitude of the result.
- sign: This is of float type which provides the sign of the result.
Return Value: The method returns a value with a magnitude and sign.
Examples :
Input: mvalue = 5 sign = -1 Output = -5.0
Below program illustrate the java.lang.StrictMath.copySign(float mvalue, float sign) method:
// Java praogram to illustrate the// java.lang.StrictMath.copySign(float mvalue, float sign)importjava.lang.*;publicclassGeeks {publicstaticvoidmain(String[] args){floata1 =7;floata2 = -1;floata3 =1;floatsvalue = StrictMath.copySign(a1, a2);System.out.println("The value of a1 with sign a2: "+ svalue);svalue = StrictMath.copySign(a1, a3);System.out.println("The value of a1 with sign a3: "+ svalue);}}chevron_rightfilter_none -
The copySign(double magnitude, double sign) is an inbuilt method of StrictMath class in Java which is used to get the first double argument with the sign of the second double argument. A NaN sign argument in this functin is considered as a positive.
Syntax :public static double copySign(double mvalue, double sign)
Parameters : This method accepts two parameters:
- mvalue: This is of double type which provides the magnitude of the result.
- sign: This is of double type which provides the sign of the result.
Return Value : The method returns a value with magnitude and sign.
Examples :Input: mvalue = 6.9 sign = -1 Output = -6.9
Below program illustrate the java.lang.StrictMath.copySign(double magnitude, double sign) method:
// Java praogram to illustrate the// java.lang.StrictMath.copySign(double magnitude, double sign)importjava.lang.*;publicclassGeeks {publicstaticvoidmain(String[] args){doublea1 =4.7, a2 = -1, a3 =1, a4 = -62;/* Returns the first double argument with thesign of the second double argument */doublesvalue = StrictMath.copySign(a1, a2);System.out.println("The value of a1 with sign a2 :"+ svalue);svalue = StrictMath.copySign(a1, a3);System.out.println("The value of a1 with sign a3 :"+ svalue);svalue = StrictMath.copySign(a2, a4);System.out.println("The value of a2 with sign a4 :"+ svalue);}}chevron_rightfilter_none
Recommended Posts:
- Java Math copySign() method with Examples
- StrictMath tan() Method in Java
- StrictMath log() Method In Java
- StrictMath pow() Method in Java
- StrictMath exp() Method in Java
- StrictMath sin() Method in Java
- Java.lang.StrictMath class in Java | Set 2
- Java.lang.StrictMath class in Java | Set 1
- StrictMath sinh() Method in Java
- StrictMath IEEEremainder() Method in Java
- StrictMath fma() method in Java with Examples
- StrictMath atan() Method in Java
- StrictMath hypot() Method in Java
- StrictMath nextDown() Method in Java
- StrictMath rint() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



