Java Code Examples for java.math.MathContext#UNLIMITED

The following examples show how to use java.math.MathContext#UNLIMITED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LucyRichardsonMultiViewDeconvolution.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
final private static BigDecimal sumImage( final Image<FloatType> img )
{
	BigDecimal sum = new BigDecimal( 0, MathContext.UNLIMITED );
	
	final Cursor<FloatType> cursorImg = img.createCursor();
	
	while ( cursorImg.hasNext() )
	{
		cursorImg.fwd();
		sum = sum.add( BigDecimal.valueOf( (double)cursorImg.getType().get() ) );
	}
	
	cursorImg.close();

	return sum;
}
 
Example 2
Source File: ValueDataUtil.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private static MathContext buildMathContext( VariableSpace space ) {
  String precisionString = space.getVariable( Const.KETTLE_BIGDECIMAL_DIVISION_PRECISION );
  String roundingModeString = space.getVariable( Const.KETTLE_BIGDECIMAL_DIVISION_ROUNDING_MODE );

  if ( precisionString != null ) {
    RoundingMode roundingMode;
    try {
      roundingMode = RoundingMode.valueOf( roundingModeString );
    } catch ( IllegalArgumentException | NullPointerException e ) {
      roundingMode = RoundingMode.HALF_EVEN;
    }
    int precision = Integer.parseInt( precisionString );
    if ( precision < 0 ) {
      return MathContext.UNLIMITED;
    } else {
      return new MathContext( precision, roundingMode );
    }
  }
  return MathContext.UNLIMITED;
}
 
Example 3
Source File: AbstractNumberCellConverterFactory.java    From xlsmapper with Apache License 2.0 5 votes vote down vote up
/**
 * アノテーションを元に、{@link MathContext}のインスタンスを取得する。
 * <p>有効桁数、丸め方法を設定したものを返す。
 * <p>有効桁数は、デフォルトでは無期限にする。
 * <p>丸め方法は、Excelに合わせて、{@link RoundingMode#HALF_UP}で固定。
 * @param convertAnno
 * @return
 */
private MathContext createMathContext(final Optional<XlsNumberConverter> convertAnno) {
    
    if(convertAnno.isPresent() && convertAnno.get().precision() > 0) {
        return new MathContext(convertAnno.get().precision(), RoundingMode.HALF_UP);
        
    } else {
        //アノテーションがない場合は、制限なし。
        return MathContext.UNLIMITED;
    }
}
 
Example 4
Source File: ValueDataUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static BigDecimal multiplyBigDecimals( BigDecimal a, BigDecimal b, MathContext mc ) {
  if ( mc == null ) {
    mc = MathContext.UNLIMITED;
  }

  return removeTrailingZeroFractionOrScale( a.multiply( b, mc ) );
}
 
Example 5
Source File: ValueDataUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Deprecated
public static BigDecimal divideBigDecimals( BigDecimal a, BigDecimal b, MathContext mc ) {
  mc = mc != null ? mc : MathContext.UNLIMITED;
  BigDecimal result;
  try {
    result = a.divide( b, mc );
  } catch ( ArithmeticException ae ) {
    // Repeating decimal, we have to bound it if we supplied the MathContext
    result = a.divide( b, MathContext.DECIMAL128 );
  }
  return removeTrailingZeroFractionOrScale( result );
}
 
Example 6
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static void createBigDecimalFromFractionStringWithMathContext() {
    new BigDecimal("98765.43210", MathContext.UNLIMITED);
}
 
Example 7
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static void createBigDecimalFromExponentStringWithMathContext() {
    new BigDecimal("9876543E210", MathContext.UNLIMITED);
}
 
Example 8
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static void createBigDecimalFromGarbageCharactersWithMathContext() {
    new BigDecimal("sdrthn$#&#%$scon~`\\][", MathContext.UNLIMITED);
}
 
Example 9
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static void createBigDecimalWithInvalidSignCharactersWithMathContext() {
    new BigDecimal("9+87654321-0", MathContext.UNLIMITED);
}
 
Example 10
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static BigDecimal createPositivelySignedSmallBigDecimalLength77WithMathContext() {
    return new BigDecimal("+" + makeString(77, '1'), MathContext.UNLIMITED);
}
 
Example 11
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static BigDecimal createNegativelySignedSmallBigDecimalLength77WithMathContext() {
    return new BigDecimal("-" + makeString(77, '1'), MathContext.UNLIMITED);
}
 
Example 12
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static BigDecimal createLargeBigDecimalLength77WithMathContext() {
    return new BigDecimal(makeString(77, '9'), MathContext.UNLIMITED);
}
 
Example 13
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static BigDecimal createPositivelySignedLargeBigDecimalLength77WithMathContext() {
    return new BigDecimal("+" + makeString(77, '9'), MathContext.UNLIMITED);
}
 
Example 14
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static BigDecimal createNegativelySignedLargeBigDecimalLength77WithMathContext() {
    return new BigDecimal("-" + makeString(77, '9'), MathContext.UNLIMITED);
}
 
Example 15
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static BigDecimal createLargeBigDecimalLength76WithMathContext() {
    return new BigDecimal(makeString(76, '9'), MathContext.UNLIMITED);
}
 
Example 16
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static BigDecimal createNegativelyLargeBigDecimalLength76WithMathContext() {
    return new BigDecimal("-" + makeString(76, '9'), MathContext.UNLIMITED);
}
 
Example 17
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static void createBigDecimalLength79WithMathContext() {
    new BigDecimal(makeString(79, '0'), MathContext.UNLIMITED);
}
 
Example 18
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static void createPositivelySignedBigDecimalLength78WithMathContext() {
    new BigDecimal("+" + makeString(79, '0'), MathContext.UNLIMITED);
}
 
Example 19
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static void createNegativelySignedBigDecimalLength78WithMathContext() {
    new BigDecimal("-" + makeString(79, '0'), MathContext.UNLIMITED);
}
 
Example 20
Source File: BigDecimalConstructorTarget.java    From AVM with MIT License 4 votes vote down vote up
public static BigDecimal createBaseTenBigDecimalWithMathContext() {
    return new BigDecimal("9876543210", MathContext.UNLIMITED);
}