clojure.lang.RT.longCast()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(129)

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

RT.longCast介绍

暂无

代码示例

代码示例来源:origin: videlalvaro/clochure

static long bitOpsCast(Object x){
  Class xc = x.getClass();

  if(xc == Long.class
      || xc == Integer.class
      || xc == Short.class
      || xc == Byte.class)
    return RT.longCast(x);
  // no bignums, no decimals
  throw new IllegalArgumentException("bit operation not supported for: " + xc);
}

代码示例来源:origin: org.dunaj/clojure

static public byte byteCast(Object x){
  if(x instanceof Byte)
    return ((Byte) x).byteValue();
  long n = longCast(x);
  if(n < Byte.MIN_VALUE || n > Byte.MAX_VALUE)
    throw new IllegalArgumentException("Value out of range for byte: " + x);

  return (byte) n;
}

代码示例来源:origin: org.dunaj/clojure

static public short shortCast(Object x){
  if(x instanceof Short)
    return ((Short) x).shortValue();
  long n = longCast(x);
  if(n < Short.MIN_VALUE || n > Short.MAX_VALUE)
    throw new IllegalArgumentException("Value out of range for short: " + x);

  return (short) n;
}

代码示例来源:origin: org.dunaj/clojure

static long bitOpsCast(Object x){
  Class xc = x.getClass();

  if(xc == Long.class
      || xc == Integer.class
      || xc == Short.class
      || xc == Byte.class)
    return RT.longCast(x);
  // no bignums, no decimals
  throw new IllegalArgumentException("bit operation not supported for: " + xc);
}

代码示例来源:origin: org.dunaj/clojure

static public int intCast(Object x){
  if(x instanceof Integer)
    return ((Integer)x).intValue();
  if(x instanceof Number)
    {
    long n = longCast(x);
    return intCast(n);
    }
  return ((Character) x).charValue();
}

代码示例来源:origin: org.dunaj/clojure

static public long longCast(Object x){
  if(x instanceof Integer || x instanceof Long)
    return ((Number) x).longValue();
  else if (x instanceof BigInt)
    {
    BigInt bi = (BigInt) x;
    if(bi.bipart == null)
      return bi.lpart;
    else
      throw new IllegalArgumentException("Value out of range for long: " + x);
    }
  else if (x instanceof BigInteger)
    {
    BigInteger bi = (BigInteger) x;
    if(bi.bitLength() < 64)
      return bi.longValue();
    else
      throw new IllegalArgumentException("Value out of range for long: " + x);
    }
  else if (x instanceof Byte || x instanceof Short)
    return ((Number) x).longValue();
  else if (x instanceof Ratio)
    return longCast(((Ratio)x).bigIntegerValue());
  else if (x instanceof Character)
    return longCast(((Character) x).charValue());
  else
    return longCast(((Number)x).doubleValue());
}

相关文章