java.math.BigDecimal.zeroScaledBy()方法的使用及代码示例

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

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

BigDecimal.zeroScaledBy介绍

[英]It returns the value 0 with the most approximated scale of type int. if longScale > Integer.MAX_VALUE the scale will be Integer.MAX_VALUE; if longScale < Integer.MIN_VALUE the scale will be Integer.MIN_VALUE; otherwise longScale is casted to the type int.
[中]如果longScale>Integer,则返回int类型的最近似比例值0。最大值刻度将为整数。最大值;如果长标度<整数。最小值刻度将为整数。最小值;否则,longScale将强制转换为int类型。

代码示例

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

/**
 * Returns a new {@code BigDecimal} whose value is {@code this * 10<sup>n</sup>}.
 * The scale of the result is {@code this.scale()} - {@code n}.
 * The precision of the result is the precision of {@code this}.
 *
 * <p>This method has the same effect as {@link #movePointRight}, except that
 * the precision is not changed.
 */
public BigDecimal scaleByPowerOfTen(int n) {
  long newScale = scale - (long)n;
  if(bitLength < 64) {
    //Taking care when a 0 is to be scaled
    if( smallValue==0  ){
      return zeroScaledBy( newScale );
    }
    return valueOf(smallValue, safeLongToInt(newScale));
  }
  return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
}

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

/**
 * Returns a new {@code BigDecimal} whose value is {@code this<sup>n</sup>}. The
 * scale of the result is {@code n * this.scale()}.
 *
 * <p>{@code x.pow(0)} returns {@code 1}, even if {@code x == 0}.
 *
 * <p>Implementation Note: The implementation is based on the ANSI standard
 * X3.274-1996 algorithm.
 *
 * @throws ArithmeticException
 *             if {@code n < 0} or {@code n > 999999999}.
 */
public BigDecimal pow(int n) {
  if (n == 0) {
    return ONE;
  }
  if ((n < 0) || (n > 999999999)) {
    throw new ArithmeticException("Invalid operation");
  }
  long newScale = scale * (long)n;
  // Let be: this = [u,s]   so:  this^n = [u^n, s*n]
  return isZero() ? zeroScaledBy(newScale)
      : new BigDecimal(getUnscaledValue().pow(n), safeLongToInt(newScale));
}

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

private BigDecimal movePoint(long newScale) {
  if (isZero()) {
    return zeroScaledBy(Math.max(newScale, 0));
  }
  /*
   * When: 'n'== Integer.MIN_VALUE isn't possible to call to
   * movePointRight(-n) since -Integer.MIN_VALUE == Integer.MIN_VALUE
   */
  if(newScale >= 0) {
    if(bitLength < 64) {
      return valueOf(smallValue, safeLongToInt(newScale));
    }
    return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
  }
  if(-newScale < MathUtils.LONG_POWERS_OF_TEN.length &&
      bitLength + LONG_POWERS_OF_TEN_BIT_LENGTH[(int)-newScale] < 64 ) {
    return valueOf(smallValue*MathUtils.LONG_POWERS_OF_TEN[(int)-newScale],0);
  }
  return new BigDecimal(Multiplication.multiplyByTenPow(
      getUnscaledValue(), safeLongToInt(-newScale)), 0);
}

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

/**
 * Returns a new {@code BigDecimal} whose value is {@code this *
 * multiplicand}. The scale of the result is the sum of the scales of the
 * two arguments.
 *
 * @param multiplicand
 *            value to be multiplied with {@code this}.
 * @return {@code this * multiplicand}.
 * @throws NullPointerException
 *             if {@code multiplicand == null}.
 */
public BigDecimal multiply(BigDecimal multiplicand) {
  long newScale = (long)this.scale + multiplicand.scale;
  if ((this.isZero()) || (multiplicand.isZero())) {
    return zeroScaledBy(newScale);
  }
  /* Let be: this = [u1,s1] and multiplicand = [u2,s2] so:
   * this x multiplicand = [ s1 * s2 , s1 + s2 ] */
  if(this.bitLength + multiplicand.bitLength < 64) {
    return valueOf(this.smallValue*multiplicand.smallValue, safeLongToInt(newScale));
  }
  return new BigDecimal(this.getUnscaledValue().multiply(
      multiplicand.getUnscaledValue()), safeLongToInt(newScale));
}

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

return zeroScaledBy(diffScale);

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

return zeroScaledBy(diffScale);

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

? zeroScaledBy(newScale)
    : new BigDecimal(integralValue, safeLongToInt(newScale)));

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Returns a new {@code BigDecimal} whose value is {@code this * 10<sup>n</sup>}.
 * The scale of the result is {@code this.scale()} - {@code n}.
 * The precision of the result is the precision of {@code this}.
 *
 * <p>This method has the same effect as {@link #movePointRight}, except that
 * the precision is not changed.
 */
public BigDecimal scaleByPowerOfTen(int n) {
  long newScale = scale - (long)n;
  if(bitLength < 64) {
    //Taking care when a 0 is to be scaled
    if( smallValue==0  ){
      return zeroScaledBy( newScale );
    }
    return valueOf(smallValue, safeLongToInt(newScale));
  }
  return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
}

代码示例来源:origin: ibinti/bugvm

/**
 * Returns a new {@code BigDecimal} whose value is {@code this * 10<sup>n</sup>}.
 * The scale of the result is {@code this.scale()} - {@code n}.
 * The precision of the result is the precision of {@code this}.
 *
 * <p>This method has the same effect as {@link #movePointRight}, except that
 * the precision is not changed.
 */
public BigDecimal scaleByPowerOfTen(int n) {
  long newScale = scale - (long)n;
  if(bitLength < 64) {
    //Taking care when a 0 is to be scaled
    if( smallValue==0  ){
      return zeroScaledBy( newScale );
    }
    return valueOf(smallValue, safeLongToInt(newScale));
  }
  return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
}

代码示例来源:origin: MobiVM/robovm

/**
 * Returns a new {@code BigDecimal} whose value is {@code this * 10<sup>n</sup>}.
 * The scale of the result is {@code this.scale()} - {@code n}.
 * The precision of the result is the precision of {@code this}.
 *
 * <p>This method has the same effect as {@link #movePointRight}, except that
 * the precision is not changed.
 */
public BigDecimal scaleByPowerOfTen(int n) {
  long newScale = scale - (long)n;
  if(bitLength < 64) {
    //Taking care when a 0 is to be scaled
    if( smallValue==0  ){
      return zeroScaledBy( newScale );
    }
    return valueOf(smallValue, safeLongToInt(newScale));
  }
  return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Returns a new {@code BigDecimal} whose value is {@code this * 10<sup>n</sup>}.
 * The scale of the result is {@code this.scale()} - {@code n}.
 * The precision of the result is the precision of {@code this}.
 *
 * <p>This method has the same effect as {@link #movePointRight}, except that
 * the precision is not changed.
 */
public BigDecimal scaleByPowerOfTen(int n) {
  long newScale = scale - (long)n;
  if(bitLength < 64) {
    //Taking care when a 0 is to be scaled
    if( smallValue==0  ){
      return zeroScaledBy( newScale );
    }
    return valueOf(smallValue, safeLongToInt(newScale));
  }
  return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Returns a new {@code BigDecimal} whose value is {@code this * 10<sup>n</sup>}.
 * The scale of the result is {@code this.scale()} - {@code n}.
 * The precision of the result is the precision of {@code this}.
 *
 * <p>This method has the same effect as {@link #movePointRight}, except that
 * the precision is not changed.
 */
public BigDecimal scaleByPowerOfTen(int n) {
  long newScale = scale - (long)n;
  if(bitLength < 64) {
    //Taking care when a 0 is to be scaled
    if( smallValue==0  ){
      return zeroScaledBy( newScale );
    }
    return valueOf(smallValue, safeLongToInt(newScale));
  }
  return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Returns a new {@code BigDecimal} whose value is {@code this * 10<sup>n</sup>}.
 * The scale of the result is {@code this.scale()} - {@code n}.
 * The precision of the result is the precision of {@code this}.
 *
 * <p>This method has the same effect as {@link #movePointRight}, except that
 * the precision is not changed.
 */
public BigDecimal scaleByPowerOfTen(int n) {
  long newScale = scale - (long)n;
  if(bitLength < 64) {
    //Taking care when a 0 is to be scaled
    if( smallValue==0  ){
      return zeroScaledBy( newScale );
    }
    return valueOf(smallValue, safeLongToInt(newScale));
  }
  return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
}

代码示例来源:origin: MobiVM/robovm

private BigDecimal movePoint(long newScale) {
  if (isZero()) {
    return zeroScaledBy(Math.max(newScale, 0));
  }
  /*
   * When: 'n'== Integer.MIN_VALUE isn't possible to call to
   * movePointRight(-n) since -Integer.MIN_VALUE == Integer.MIN_VALUE
   */
  if(newScale >= 0) {
    if(bitLength < 64) {
      return valueOf(smallValue, safeLongToInt(newScale));
    }
    return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
  }
  if(-newScale < MathUtils.LONG_POWERS_OF_TEN.length &&
      bitLength + LONG_POWERS_OF_TEN_BIT_LENGTH[(int)-newScale] < 64 ) {
    return valueOf(smallValue*MathUtils.LONG_POWERS_OF_TEN[(int)-newScale],0);
  }
  return new BigDecimal(Multiplication.multiplyByTenPow(
      getUnscaledValue(), safeLongToInt(-newScale)), 0);
}

代码示例来源:origin: ibinti/bugvm

private BigDecimal movePoint(long newScale) {
  if (isZero()) {
    return zeroScaledBy(Math.max(newScale, 0));
  }
  /*
   * When: 'n'== Integer.MIN_VALUE isn't possible to call to
   * movePointRight(-n) since -Integer.MIN_VALUE == Integer.MIN_VALUE
   */
  if(newScale >= 0) {
    if(bitLength < 64) {
      return valueOf(smallValue, safeLongToInt(newScale));
    }
    return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
  }
  if(-newScale < MathUtils.LONG_POWERS_OF_TEN.length &&
      bitLength + LONG_POWERS_OF_TEN_BIT_LENGTH[(int)-newScale] < 64 ) {
    return valueOf(smallValue*MathUtils.LONG_POWERS_OF_TEN[(int)-newScale],0);
  }
  return new BigDecimal(Multiplication.multiplyByTenPow(
      getUnscaledValue(), safeLongToInt(-newScale)), 0);
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

private BigDecimal movePoint(long newScale) {
  if (isZero()) {
    return zeroScaledBy(Math.max(newScale, 0));
  }
  /*
   * When: 'n'== Integer.MIN_VALUE isn't possible to call to
   * movePointRight(-n) since -Integer.MIN_VALUE == Integer.MIN_VALUE
   */
  if(newScale >= 0) {
    if(bitLength < 64) {
      return valueOf(smallValue, safeLongToInt(newScale));
    }
    return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
  }
  if(-newScale < MathUtils.LONG_POWERS_OF_TEN.length &&
      bitLength + LONG_POWERS_OF_TEN_BIT_LENGTH[(int)-newScale] < 64 ) {
    return valueOf(smallValue*MathUtils.LONG_POWERS_OF_TEN[(int)-newScale],0);
  }
  return new BigDecimal(Multiplication.multiplyByTenPow(
      getUnscaledValue(), safeLongToInt(-newScale)), 0);
}

代码示例来源:origin: com.gluonhq/robovm-rt

private BigDecimal movePoint(long newScale) {
  if (isZero()) {
    return zeroScaledBy(Math.max(newScale, 0));
  }
  /*
   * When: 'n'== Integer.MIN_VALUE isn't possible to call to
   * movePointRight(-n) since -Integer.MIN_VALUE == Integer.MIN_VALUE
   */
  if(newScale >= 0) {
    if(bitLength < 64) {
      return valueOf(smallValue, safeLongToInt(newScale));
    }
    return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
  }
  if(-newScale < MathUtils.LONG_POWERS_OF_TEN.length &&
      bitLength + LONG_POWERS_OF_TEN_BIT_LENGTH[(int)-newScale] < 64 ) {
    return valueOf(smallValue*MathUtils.LONG_POWERS_OF_TEN[(int)-newScale],0);
  }
  return new BigDecimal(Multiplication.multiplyByTenPow(
      getUnscaledValue(), safeLongToInt(-newScale)), 0);
}

代码示例来源:origin: com.bugvm/bugvm-rt

private BigDecimal movePoint(long newScale) {
  if (isZero()) {
    return zeroScaledBy(Math.max(newScale, 0));
  }
  /*
   * When: 'n'== Integer.MIN_VALUE isn't possible to call to
   * movePointRight(-n) since -Integer.MIN_VALUE == Integer.MIN_VALUE
   */
  if(newScale >= 0) {
    if(bitLength < 64) {
      return valueOf(smallValue, safeLongToInt(newScale));
    }
    return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
  }
  if(-newScale < MathUtils.LONG_POWERS_OF_TEN.length &&
      bitLength + LONG_POWERS_OF_TEN_BIT_LENGTH[(int)-newScale] < 64 ) {
    return valueOf(smallValue*MathUtils.LONG_POWERS_OF_TEN[(int)-newScale],0);
  }
  return new BigDecimal(Multiplication.multiplyByTenPow(
      getUnscaledValue(), safeLongToInt(-newScale)), 0);
}

代码示例来源:origin: FlexoVM/flexovm

private BigDecimal movePoint(long newScale) {
  if (isZero()) {
    return zeroScaledBy(Math.max(newScale, 0));
  }
  /*
   * When: 'n'== Integer.MIN_VALUE isn't possible to call to
   * movePointRight(-n) since -Integer.MIN_VALUE == Integer.MIN_VALUE
   */
  if(newScale >= 0) {
    if(bitLength < 64) {
      return valueOf(smallValue, safeLongToInt(newScale));
    }
    return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
  }
  if(-newScale < MathUtils.LONG_POWERS_OF_TEN.length &&
      bitLength + LONG_POWERS_OF_TEN_BIT_LENGTH[(int)-newScale] < 64 ) {
    return valueOf(smallValue*MathUtils.LONG_POWERS_OF_TEN[(int)-newScale],0);
  }
  return new BigDecimal(Multiplication.multiplyByTenPow(
      getUnscaledValue(), safeLongToInt(-newScale)), 0);
}

代码示例来源:origin: MobiVM/robovm

/**
 * Returns a new {@code BigDecimal} whose value is {@code this *
 * multiplicand}. The scale of the result is the sum of the scales of the
 * two arguments.
 *
 * @param multiplicand
 *            value to be multiplied with {@code this}.
 * @return {@code this * multiplicand}.
 * @throws NullPointerException
 *             if {@code multiplicand == null}.
 */
public BigDecimal multiply(BigDecimal multiplicand) {
  long newScale = (long)this.scale + multiplicand.scale;
  if ((this.isZero()) || (multiplicand.isZero())) {
    return zeroScaledBy(newScale);
  }
  /* Let be: this = [u1,s1] and multiplicand = [u2,s2] so:
   * this x multiplicand = [ s1 * s2 , s1 + s2 ] */
  if(this.bitLength + multiplicand.bitLength < 64) {
    return valueOf(this.smallValue*multiplicand.smallValue, safeLongToInt(newScale));
  }
  return new BigDecimal(this.getUnscaledValue().multiply(
      multiplicand.getUnscaledValue()), safeLongToInt(newScale));
}

相关文章