目录

static double copySign(double magnitude, double sign)

描述 (Description)

java.lang.Math.copySign(double magnitude, double sign)返回带有第二个浮点参数符号的第一个浮点参数。

声明 (Declaration)

以下是java.lang.Math.copySign()方法的声明

public static double copySign(double magnitude, double sign)

参数 (Parameters)

  • magnitude - 提供结果magnitude的参数

  • sign - 提供结果sign的参数

返回值 (Return Value)

此方法返回一个具有幅度值和符号符号的值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了lang.Math.copySign()方法的用法。

package com.iowiki;
import java.lang.*;
public class MathDemo {
   public static void main(String[] args) {
      // get two double numbers
      double x = 125.9;
      double y = -0.4873;
      // print a double with the magnitude of x and the sign of y
      System.out.println("Math.copySign(" + x + "," + y + ")=" + Math.copySign(x, y));
      // print a double with the magnitude of y and the sign of x
      System.out.println("Math.copySign(" + y + "," + x + ")=" + Math.copySign(y, x));
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Math.copySign(125.9, -0.4873)=-125.9
Math.copySign(-0.4873, 125.9)=0.4873
↑回到顶部↑
WIKI教程 @2018