Package java.math

Examples of java.math.MathContext


                    BigDecimal amountApplied = paymentApplication.getBigDecimal("amountApplied");
                    // check currency invoice and if different convert amount applied for display
                    if (actual.equals(Boolean.FALSE) && paymentApplication.get("invoiceId") != null && payment.get("actualCurrencyAmount") != null && payment.get("actualCurrencyUomId") != null) {
                        GenericValue invoice = paymentApplication.getRelatedOne("Invoice");
                        if (payment.getString("actualCurrencyUomId").equals(invoice.getString("currencyUomId"))) {
                               amountApplied = amountApplied.multiply(payment.getBigDecimal("amount")).divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100));
                        }
                    }
                    paymentApplied = paymentApplied.add(amountApplied).setScale(decimals,rounding);
                }
            }
View Full Code Here


     * @return the BigDecimal value in radians
     * @since 2012-03-22
     * @author l.bruninx
     */
    static public BigDecimal toRadians(BigDecimal x, MathContext mc) {
        MathContext nmc = _mc_adjust_(x,_mc_plus2_(mc)); // more precision (the integer part include by _mc_adjust_)...
        BigDecimal c=new BigDecimal(180,nmc);
        c=x.divide(c,nmc).multiply(pi(nmc));
        return _dec_round_(c,mc);                        // mc precision (the integer part include by _dec_round_)...
    }
View Full Code Here

        */
        public String toFString(int digits)
        {
                if ( b.compareTo(BigInteger.ONE) != 0)
                {
                        MathContext mc = new MathContext(digits,RoundingMode.DOWN) ;
                        BigDecimal f = (new BigDecimal(a)).divide(new BigDecimal(b),mc) ;
                        return( f.toString() ) ;
                }
                else
                        return a.toString() ;
View Full Code Here

     * @author l.bruninx, 2012-03-22.
     * @since 2012-03-22
     *
     */
    private static final MathContext _mc_plus2_(MathContext mc){
        return new MathContext(mc.getPrecision() + 1, mc.getRoundingMode()); // more precision...
    }
View Full Code Here

        return x.precision()-x.scale();
    }
   
    final private static BigDecimal _dec_round_(BigDecimal r, MathContext mc){
        int digits=r.precision()-r.scale();
        return r.round(new MathContext(digits+mc.getPrecision(),mc.getRoundingMode()));
    }
View Full Code Here

    }
   
    final private static MathContext _mc_adjust_(BigDecimal r, MathContext mc){
        int digits=r.precision()-r.scale();
        Interpreter.Log("BigDecimalMath._mc_adjust_:"+digits);
        return new MathContext(digits+mc.getPrecision(),mc.getRoundingMode());
    }
View Full Code Here

        if(t1>10000)                              
            digits=10000;
        else
            digits=(int)t1;
        Interpreter.Log("BigDecimalMath._mc_adjust_exp_:"+digits);
        return new MathContext(digits+mc.getPrecision(),mc.getRoundingMode());
    }
View Full Code Here

        if(t1>10000)
            digits=10000;
        else
            digits=(int)t1;
        Interpreter.Log("BigDecimalMath._mc_adjust_pow_:"+digits);
        return new MathContext(digits+mc.getPrecision(),mc.getRoundingMode());
    }
View Full Code Here

            //double eps = prec2err(0.577, mc.getPrecision()); // removed by l.bruninx, 2012-03-26

            /*
             * Euler-Stieltjes as shown in Dilcher, Aequat Math 48 (1) (1994) 55-85
             */
            MathContext mcloc = new MathContext(2 + mc.getPrecision());
            BigDecimal resul = BigDecimal.ONE;
            resul = resul.add(log(new BigDecimal(2), mcloc));
            resul = resul.subtract(log(new BigDecimal(3), mcloc));

            /* how many terms: zeta-1 falls as 1/2^(2n+1), so the
             * terms drop faster than 1/2^(4n+2). Set 1/2^(4kmax+2) < eps.
             * Leading term zeta(3)/(4^1*3) is 0.017. Leading zeta(3) is 1.2. Log(2) is 0.7
             */
            //int kmax = (int) ((Math.log(eps / 0.7) - 2.) / 4.);       // removed by l.bruninx, 2012-03-26
            //mcloc = new MathContext(1 + err2prec(1.2, eps / kmax));   // removed by l.bruninx, 2012-03-26
            int n = Const.GAMMA.precision();//1; // modified by l.bruninx, 2012-03-26
            /**
             * n : precision ???
             */
            BigDecimal old_resul=Const.GAMMA;
            Bernoulli bern_cache=new Bernoulli();
            Factorial fact_cache=new Factorial();
            //bern_cache.at(mc.getPrecision()*2);
            //fact_cache.at(mc.getPrecision()*2);
            Interpreter.Log("Start gamma:");
            do{        // modified by l.bruninx, 2012-03-26
                old_resul=resul.round(mc);
                /*
                 * zeta is close to 1. Division of zeta-1 through
                 * 4^n*(2n+1) means divion through roughly 2^(2n+1)
                 */
                //System.out.print("A("+(2 * n + 1)+"):");
                BigDecimal c = zeta(2 * n + 1, mcloc,bern_cache,fact_cache).subtract(BigDecimal.ONE,mcloc);
                //System.out.print("B");
                BigInteger fourn = new BigInteger("" + (2 * n + 1));
                fourn = fourn.shiftLeft(2 * n);
                c = c.divide(new BigDecimal(fourn),mcloc);
                resul = resul.subtract(c,mcloc);
                //if (c.doubleValue() < 0.1 * eps)                      // removed by l.bruninx, 2012-03-26
                //    break;                                            // removed by l.bruninx, 2012-03-26
               

                if(Interpreter.isDebugMode()){
                    Interpreter.Log("gamma Step:"+resul.round(new MathContext(_common_precision_of_(old_resul,resul))).toPlainString());
                }
               
                n++;
            }while(resul.round(mc).compareTo(old_resul)!=0); // modified by l.bruninx, 2012-03-26
            return resul.round(mc);
View Full Code Here

        /* start the computation from a double precision estimate */
        BigDecimal s = new BigDecimal(Math.sqrt(x.doubleValue()), mc);
        final BigDecimal half = new BigDecimal("2");

        /* increase the local accuracy by 2 digits */
        MathContext locmc = new MathContext(mc.getPrecision() + 2, mc.getRoundingMode());

        /*
         * relative accuracy requested is 10^(-precision)
         */
        //final double eps = Math.pow(10.0, -mc.getPrecision()); // removed by l.bruninx, 2012-03-23
View Full Code Here

TOP

Related Classes of java.math.MathContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.