java.lang.Math.signum()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中java.lang.Math.signum()方法的一些代码示例,展示了Math.signum()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.signum()方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:signum

Math.signum介绍

[英]Returns the signum function of the argument. If the argument is less than zero, it returns -1.0. If the argument is greater than zero, 1.0 is returned. If the argument is either positive or negative zero, the argument is returned as result.

Special cases:

  • signum(+0.0) = +0.0
  • signum(-0.0) = -0.0
  • signum(+infinity) = +1.0
  • signum(-infinity) = -1.0
  • signum(NaN) = NaN
    [中]返回参数的signum函数。如果参数小于零,则返回-1.0。如果参数大于零,则返回1.0。如果参数为正或负零,则返回参数作为结果。
    特殊情况:
    *符号(+0.0)=+0.0
    *符号(-0.0)=-0.0
    *符号(+无穷大)=+1.0
    *符号(-无穷大)=-1.0
    *符号(NaN)=NaN

代码示例

代码示例来源:origin: libgdx/libgdx

/** Determines on which side of the given line the point is. Returns -1 if the point is on the left side of the line, 0 if the
 * point is on the line and 1 if the point is on the right side of the line. Left and right are relative to the lines direction
 * which is linePoint1 to linePoint2. */
public static int pointLineSide (Vector2 linePoint1, Vector2 linePoint2, Vector2 point) {
  return (int)Math.signum(
    (linePoint2.x - linePoint1.x) * (point.y - linePoint1.y) - (linePoint2.y - linePoint1.y) * (point.x - linePoint1.x));
}

代码示例来源:origin: libgdx/libgdx

static private int computeSpannedAreaSign (float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) {
    float area = p1x * (p3y - p2y);
    area += p2x * (p1y - p3y);
    area += p3x * (p2y - p1y);
    return (int)Math.signum(area);
  }
}

代码示例来源:origin: libgdx/libgdx

static private int computeSpannedAreaSign (float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) {
    float area = p1x * (p3y - p2y);
    area += p2x * (p1y - p3y);
    area += p3x * (p2y - p1y);
    return (int)Math.signum(area);
  }
}

代码示例来源:origin: libgdx/libgdx

/** Determines on which side of the given line the point is. Returns -1 if the point is on the left side of the line, 0 if the
 * point is on the line and 1 if the point is on the right side of the line. Left and right are relative to the lines direction
 * which is linePoint1 to linePoint2. */
public static int pointLineSide (Vector2 linePoint1, Vector2 linePoint2, Vector2 point) {
  return (int)Math.signum(
    (linePoint2.x - linePoint1.x) * (point.y - linePoint1.y) - (linePoint2.y - linePoint1.y) * (point.x - linePoint1.x));
}

代码示例来源:origin: libgdx/libgdx

public static int pointLineSide (float linePoint1X, float linePoint1Y, float linePoint2X, float linePoint2Y, float pointX,
  float pointY) {
  return (int)Math
    .signum((linePoint2X - linePoint1X) * (pointY - linePoint1Y) - (linePoint2Y - linePoint1Y) * (pointX - linePoint1X));
}

代码示例来源:origin: libgdx/libgdx

public static int pointLineSide (float linePoint1X, float linePoint1Y, float linePoint2X, float linePoint2Y, float pointX,
  float pointY) {
  return (int)Math
    .signum((linePoint2X - linePoint1X) * (pointY - linePoint1Y) - (linePoint2Y - linePoint1Y) * (pointX - linePoint1X));
}

代码示例来源:origin: libgdx/libgdx

@Override
  public int compare (Decal o1, Decal o2) {
    float dist1 = camera.position.dst(o1.position);
    float dist2 = camera.position.dst(o2.position);
    return (int)Math.signum(dist2 - dist1);
  }
});

代码示例来源:origin: libgdx/libgdx

@Override
  public int compare (Decal o1, Decal o2) {
    float dist1 = camera.position.dst(o1.position);
    float dist2 = camera.position.dst(o2.position);
    return (int)Math.signum(dist2 - dist1);
  }
});

代码示例来源:origin: prestodb/presto

@Description("round to integer by dropping digits after decimal point")
@ScalarFunction
@SqlType(StandardTypes.REAL)
public static long truncate(@SqlType(StandardTypes.REAL) long num)
{
  float numInFloat = intBitsToFloat((int) num);
  return floatToRawIntBits((float) (Math.signum(numInFloat) * Math.floor(Math.abs(numInFloat))));
}

代码示例来源:origin: prestodb/presto

@Description("round to integer by dropping digits after decimal point")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double truncate(@SqlType(StandardTypes.DOUBLE) double num)
{
  return Math.signum(num) * Math.floor(Math.abs(num));
}

代码示例来源:origin: prestodb/presto

@Description("signum")
@ScalarFunction("sign")
@SqlType(StandardTypes.REAL)
public static long signFloat(@SqlType(StandardTypes.REAL) long num)
{
  return floatToRawIntBits((Math.signum(intBitsToFloat((int) num))));
}

代码示例来源:origin: prestodb/presto

@LiteralParameters({"p", "s"})
@SqlType("decimal(1,0)")
public static long signDecimalShort(@SqlType("decimal(p, s)") long num)
{
  return (long) Math.signum(num);
}

代码示例来源:origin: prestodb/presto

@ScalarFunction
@SqlType(StandardTypes.BIGINT)
public static long sign(@SqlType(StandardTypes.BIGINT) long num)
{
  return (long) Math.signum(num);
}

代码示例来源:origin: google/guava

public void testCompare() {
 // This is the only ordering for primitives that does not have a
 // corresponding Comparable wrapper in java.lang.
 for (int i = 0; i < VALUES.length; i++) {
  for (int j = 0; j < VALUES.length; j++) {
   byte x = VALUES[i];
   byte y = VALUES[j];
   // note: spec requires only that the sign is the same
   assertEquals(
     x + ", " + y,
     Math.signum(UnsignedBytes.compare(x, y)),
     Math.signum(Ints.compare(i, j)));
  }
 }
}

代码示例来源:origin: prestodb/presto

private void testCompare(String decimalA, String decimalB, int expected)
{
  int actual = TYPE.compareTo(decimalAsBlock(decimalA), 0, decimalAsBlock(decimalB), 0);
  assertEquals((int) signum(actual), (int) signum(expected), "bad comparison result for " + decimalA + ", " + decimalB);
}

代码示例来源:origin: prestodb/presto

@Description("signum")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double sign(@SqlType(StandardTypes.DOUBLE) double num)
{
  return Math.signum(num);
}

代码示例来源:origin: prestodb/presto

@Description("signum")
@ScalarFunction("sign")
@SqlType(StandardTypes.INTEGER)
public static long signInteger(@SqlType(StandardTypes.INTEGER) long num)
{
  return (long) Math.signum(num);
}

代码示例来源:origin: prestodb/presto

@Description("signum")
@ScalarFunction("sign")
@SqlType(StandardTypes.SMALLINT)
public static long signSmallint(@SqlType(StandardTypes.SMALLINT) long num)
{
  return (long) Math.signum(num);
}

代码示例来源:origin: prestodb/presto

@Description("signum")
@ScalarFunction("sign")
@SqlType(StandardTypes.TINYINT)
public static long signTinyint(@SqlType(StandardTypes.TINYINT) long num)
{
  return (long) Math.signum(num);
}

代码示例来源:origin: apache/kafka

public void verifyReauthenticationMetrics(int successfulReauthentications, final int failedReauthentications)
    throws InterruptedException {
  waitForMetrics("successful-reauthentication", successfulReauthentications,
      EnumSet.of(MetricType.TOTAL, MetricType.RATE));
  waitForMetrics("failed-reauthentication", failedReauthentications,
      EnumSet.of(MetricType.TOTAL, MetricType.RATE));
  waitForMetrics("successful-authentication-no-reauth", 0, EnumSet.of(MetricType.TOTAL));
  waitForMetrics("reauthentication-latency", Math.signum(successfulReauthentications),
      EnumSet.of(MetricType.MAX, MetricType.AVG));
}

相关文章