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

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

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

BigDecimal.approxPrecision介绍

[英]If the precision already was calculated it returns that value, otherwise it calculates a very good approximation efficiently . Note that this value will be precision() or precision()-1in the worst case.
[中]如果已经计算了精度,它将返回该值,否则它将高效地计算出非常好的近似值。请注意,在最坏的情况下,此值将是precision()或precision()-1。

代码示例

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

/**
 * Returns this {@code BigDecimal} as an long value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an long, then {@code this % 2<sup>64</sup>} is returned.
 */
@Override
public long longValue() {
  /*
   * If scale <= -64 there are at least 64 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue());
}

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

/**
 * Returns this {@code BigDecimal} as an int value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an int, then {@code this % 2<sup>32</sup>} is returned.
 */
@Override
public int intValue() {
  /*
   * If scale <= -32 there are at least 32 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue());
}

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

int diffPrecision = this.approxPrecision() - val.approxPrecision();
if (diffPrecision > diffScale + 1) {
  return thisSign;

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

if (this.approxPrecision() < diffScale - 1) {
  larger = augend;
  smaller = this;
} else if (augend.approxPrecision() < -diffScale - 1) {
  larger = this;
  smaller = augend;
  return add(augend).round(mc);
if (mc.getPrecision() >= larger.approxPrecision()) {

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

if (subtrahend.approxPrecision() < diffScale - 1) {
  if (mc.getPrecision() < this.approxPrecision()) {
    thisSignum = this.signum();
    if (thisSignum != subtrahend.signum()) {

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

if (approxPrecision() < mcPrecision || mcPrecision == 0) {
  return;

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

/**
 * Returns this {@code BigDecimal} as a big integer instance if it has no
 * fractional part. If this {@code BigDecimal} has a fractional part, i.e.
 * if rounding would be necessary, an {@code ArithmeticException} is thrown.
 *
 * @return this {@code BigDecimal} as a big integer value.
 * @throws ArithmeticException
 *             if rounding is necessary.
 */
public BigInteger toBigIntegerExact() {
  if ((scale == 0) || (isZero())) {
    return getUnscaledValue();
  } else if (scale < 0) {
    return getUnscaledValue().multiply(Multiplication.powerOf10(-(long)scale));
  } else {// (scale > 0)
    BigInteger[] integerAndFraction;
    // An optimization before do a heavy division
    if ((scale > approxPrecision()) || (scale > getUnscaledValue().getLowestSetBit())) {
      throw new ArithmeticException("Rounding necessary");
    }
    integerAndFraction = getUnscaledValue().divideAndRemainder(Multiplication.powerOf10(scale));
    if (integerAndFraction[1].signum() != 0) {
      // It exists a non-zero fractional part
      throw new ArithmeticException("Rounding necessary");
    }
    return integerAndFraction[0];
  }
}

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

+ divisor.approxPrecision() - approxPrecision();
long diffScale = (long)scale - divisor.scale;
long newScale = diffScale; // scale of the final quotient

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

throw new ArithmeticException("Division by zero");
if ((divisor.approxPrecision() + newScale > this.approxPrecision() + 1L)
|| (this.isZero())) {

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

/**
 * Returns this {@code BigDecimal} as an int value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an int, then {@code this % 2<sup>32</sup>} is returned.
 */
@Override
public int intValue() {
  /*
   * If scale <= -32 there are at least 32 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue());
}

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

/**
 * Returns this {@code BigDecimal} as an long value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an long, then {@code this % 2<sup>64</sup>} is returned.
 */
@Override
public long longValue() {
  /*
   * If scale <= -64 there are at least 64 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue());
}

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

/**
 * Returns this {@code BigDecimal} as an int value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an int, then {@code this % 2<sup>32</sup>} is returned.
 */
@Override
public int intValue() {
  /*
   * If scale <= -32 there are at least 32 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue());
}

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

/**
 * Returns this {@code BigDecimal} as an int value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an int, then {@code this % 2<sup>32</sup>} is returned.
 */
@Override
public int intValue() {
  /*
   * If scale <= -32 there are at least 32 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue());
}

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

/**
 * Returns this {@code BigDecimal} as an long value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an long, then {@code this % 2<sup>64</sup>} is returned.
 */
@Override
public long longValue() {
  /*
   * If scale <= -64 there are at least 64 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue());
}

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

/**
 * Returns this {@code BigDecimal} as an int value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an int, then {@code this % 2<sup>32</sup>} is returned.
 */
@Override
public int intValue() {
  /*
   * If scale <= -32 there are at least 32 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue());
}

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

/**
 * Returns this {@code BigDecimal} as an int value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an int, then {@code this % 2<sup>32</sup>} is returned.
 */
@Override
public int intValue() {
  /*
   * If scale <= -32 there are at least 32 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue());
}

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

/**
 * Returns this {@code BigDecimal} as an int value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an int, then {@code this % 2<sup>32</sup>} is returned.
 */
@Override
public int intValue() {
  /*
   * If scale <= -32 there are at least 32 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue());
}

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

/**
 * Returns this {@code BigDecimal} as an long value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an long, then {@code this % 2<sup>64</sup>} is returned.
 */
@Override
public long longValue() {
  /*
   * If scale <= -64 there are at least 64 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue());
}

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

/**
 * Returns this {@code BigDecimal} as an long value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an long, then {@code this % 2<sup>64</sup>} is returned.
 */
@Override
public long longValue() {
  /*
   * If scale <= -64 there are at least 64 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue());
}

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

/**
 * Returns this {@code BigDecimal} as an long value. Any fractional part is
 * discarded. If the integral part of {@code this} is too big to be
 * represented as an long, then {@code this % 2<sup>64</sup>} is returned.
 */
@Override
public long longValue() {
  /*
   * If scale <= -64 there are at least 64 trailing bits zero in
   * 10^(-scale). If the scale is positive and very large the long value
   * could be zero.
   */
  return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue());
}

相关文章

微信公众号

最新文章

更多