Package java.math

Examples of java.math.BigDecimal.precision()


             */
            BigDecimal R = addRound(z.re, divideRound(multiplyRound(z.im, z.im), z.re));
            BigDecimal I = addRound(z.im, divideRound(multiplyRound(z.re, z.re), z.im));
            MathContext mc = new MathContext(1 + R.precision());
            R = BigDecimal.ONE.divide(R, mc);
            mc = new MathContext(1 + I.precision());
            I = BigDecimal.ONE.divide(I, mc);
            return new BigComplex(R, I.negate());
        }
    }

View Full Code Here


        /*
         * la précision doit être >= 0...
         */
        if(p<0) throw new InterpreterException(StdErrors.extend(StdErrors.Out_of_range, "precision "+p+" must be >= 0" ));
        BigDecimal r=number.get();
        int digits=r.precision()-r.scale();
        MathContext mc=context.get();
        MathContext nmc = new MathContext(digits<0 ? p+1 : p + digits, mc.getRoundingMode()); // more precision...
        context.getAndSet( nmc );                 
        return null;
    }
View Full Code Here

     * @throws Exception
     */
    public Node external_get_precision(Node startAt) throws Exception {
        startAt.isGoodArgsCnt(1);
        BigDecimal r=number.get();
        int digits=r.precision()-r.scale();
        MathContext mc=context.get();
        return new Node(digits<0 ? Math.abs(digits)-1 : mc.getPrecision() - digits);
    }
   
    /**
 
View Full Code Here

    public Node external_precision(Node startAt) throws Exception {
        startAt.isGoodArgsCnt(2);
        int c=(int)startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
        if(c<0) throw new InterpreterException(StdErrors.extend(StdErrors.Out_of_range, "precision "+c+" must be >= 0" ));
        BigDecimal r=number.get();
        int digits=r.precision()-r.scale();
        MathContext mc=context.get();
        MathContext nmc = new MathContext(digits<0 ? c+1 : c + digits, mc.getRoundingMode()); // more precision...
        return Node.createExternal(new External_Decimal(number.get().round(nmc),nmc));
    }
   
View Full Code Here

    public Node external_mutator_precision(Node startAt) throws Exception {
        startAt.isGoodArgsCnt(2);
        int c=(int)startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
        if(c<0) throw new InterpreterException(StdErrors.extend(StdErrors.Out_of_range, "precision "+c+" must be >= 0" ));
        BigDecimal r=number.get();
        int digits=r.precision()-r.scale();
        MathContext mc=context.get();
        context.getAndSet( new MathContext(digits<0 ? c+1 : c + digits, mc.getRoundingMode()) );
        number.getAndSet(number.get().round(context.get()));
        return null;
    }
View Full Code Here

        else{
            //string et objet...
            String sn=Node.node2VString(arg0).getString();
            MathContext mc=context.get();
            BigDecimal v=new BigDecimal(sn);
            if(v.precision()>mc.getPrecision())
                context.getAndSet( new MathContext(v.precision(),mc.getRoundingMode()) );
            number.getAndSet( v );
        }
        return null;
    }
View Full Code Here

            //string et objet...
            String sn=Node.node2VString(arg0).getString();
            MathContext mc=context.get();
            BigDecimal v=new BigDecimal(sn);
            if(v.precision()>mc.getPrecision())
                context.getAndSet( new MathContext(v.precision(),mc.getRoundingMode()) );
            number.getAndSet( v );
        }
        return null;
    }
View Full Code Here

        startAt.isGoodArgsCnt(1);
        BigDecimal n = number.get();
        //int digits=Math.abs(n.precision()-n.scale());
        //System.out.println("integer part:"+digits+", precision:"+number.precision());
        MathContext mc=context.get();
        return new Node(n.round(new MathContext(Math.max(n.precision(),mc.getPrecision()),mc.getRoundingMode())).stripTrailingZeros().toPlainString());
    }

    /**
     * Retourne le Decimal sous la forme d'une chaîne de caractères dans la Engineering (avec puissances de 10).
     *
 
View Full Code Here

        else if (arg.isString()) {
            //string
            String sn=arg.getString();
            BigDecimal v=new BigDecimal(sn);
            MathContext mc=context.get();
            if(v.precision()<mc.getPrecision())
                return new BigDecimal(sn,mc);
            else
                return v;
        }
       
View Full Code Here

            /**
             * Attention! La division doit être limitée par me contexte, sinon une division comme 1/3 donne lieu à une execption.
             */
            try {
                BigDecimal v=number.get();
                int digits=Math.abs(v.precision()-v.scale());
                MathContext nmc = new MathContext(mc.getPrecision() + digits, mc.getRoundingMode()); // more precision...
                return Node.createExternal(new External_Decimal(d.divide(number.get(), nmc),mc));
            }
            catch (ArithmeticException ex) {
                // prévoir la gestion de l'exception division par zéro sur exception seulement.
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.