Package java.math

Examples of java.math.MathContext


            int kmax = Math.min(i,j);
            BigDecimal s = BigDecimal.ZERO;
            for (int k = 0; k < kmax; k++) {
                int scale = MatrixBigDecimal.GLOBAL_SCALE;
                s = s.add(LUrowi[k].multiply(LUcolj[k], new MathContext(scale)));
            }

            LUcolj[i] = LUcolj[i].subtract(s);
            LUrowi[j] = LUcolj[i];
         }
View Full Code Here


         throw new IllegalArgumentException("Matrix must be square.");
      }
      BigDecimal d = new BigDecimal(pivsign);
      for (int j = 0; j < n; j++) {
          int scale = MatrixBigDecimal.GLOBAL_SCALE;
          d = d.multiply(LU[j][j], new MathContext(scale));
      }
      return d;
   }
View Full Code Here

      // Solve L*Y = B(piv,:)
      for (int k = 0; k < n; k++) {
         for (int i = k+1; i < n; i++) {
            for (int j = 0; j < nx; j++) {
                int scale = MatrixBigDecimal.GLOBAL_SCALE;
                X[i][j] = X[i][j].subtract(X[k][j].multiply(LU[i][k], new MathContext(scale)));
            }
         }
      }
      // Solve U*X = Y;
      for (int k = n-1; k >= 0; k--) {
         for (int j = 0; j < nx; j++) {
             int scale = MatrixBigDecimal.GLOBAL_SCALE;
            X[k][j] = X[k][j].divide(LU[k][k], scale, roundingMode);
         }
         for (int i = 0; i < k; i++) {
            for (int j = 0; j < nx; j++) {
                int scale = MatrixBigDecimal.GLOBAL_SCALE;
                X[i][j] = X[i][j].subtract(X[k][j].multiply(LU[i][k], new MathContext(scale)));
            }
         }
      }
      return Xmat;
   }
View Full Code Here

   public static BigDecimal hypot(BigDecimal a, BigDecimal b, int roundingMode) {
       BigDecimal r;
      if (a.abs().compareTo(b.abs()) > 0) {
          int scale = MatrixBigDecimal.GLOBAL_SCALE;
         r = b.divide(a, scale);
         r = a.abs().multiply(sqrt(r.multiply(r, new MathContext(scale)).add(BigDecimal.ONE), scale, roundingMode), new MathContext(scale));
      } else if (b.compareTo(BigDecimal.ZERO) != 0) {
          int scale = MatrixBigDecimal.GLOBAL_SCALE;
         r = a.divide(b, scale);
         r = b.abs().multiply(sqrt(r.multiply(r, new MathContext(scale)).add(BigDecimal.ONE), scale, roundingMode), new MathContext(scale));
      } else {
         r = BigDecimal.ZERO;
      }
      return r;
   }
View Full Code Here

            // Apply transformation to remaining columns.
            for (int j = k+1; j < n; j++) {
               BigDecimal s = BigDecimal.ZERO;
               for (int i = k; i < m; i++) {
                   int scale = MatrixBigDecimal.GLOBAL_SCALE;
                   s = s.add(QR[i][k].multiply(QR[i][j], new MathContext(scale)));
               }
               int scale = MatrixBigDecimal.GLOBAL_SCALE;
               s = s.negate().divide(QR[k][k], scale, roundingMode);
               for (int i = k; i < m; i++) {
                   int scale2 = MatrixBigDecimal.GLOBAL_SCALE;
                   QR[i][j] = QR[i][j].add(s.multiply(QR[i][k], new MathContext(scale2)));
               }
            }
         }
         Rdiag[k] = nrm.negate();
      }
View Full Code Here

      for (int k = 0; k < n; k++) {
         for (int j = 0; j < nx; j++) {
            BigDecimal s = BigDecimal.ZERO;
            for (int i = k; i < m; i++) {
                int scale = MatrixBigDecimal.GLOBAL_SCALE;
                s = s.add(QR[i][k].multiply(X[i][j]), new MathContext(scale));
            }
            int scale = Math.max(s.scale(), QR[k][k].scale());
            s = s.negate().divide(QR[k][k], scale, roundingMode);
            for (int i = k; i < m; i++) {
                int scale2 = MatrixBigDecimal.GLOBAL_SCALE;
                X[i][j] = X[i][j].add(s.multiply(QR[i][k], new MathContext(scale2)));
            }
         }
      }
      // Solve R*X = Y;
      for (int k = n-1; k >= 0; k--) {
         for (int j = 0; j < nx; j++) {
             int scale = MatrixBigDecimal.GLOBAL_SCALE;
             X[k][j] = X[k][j].divide(Rdiag[k], scale, roundingMode);
         }
         for (int i = 0; i < k; i++) {
            for (int j = 0; j < nx; j++) {
                int scale = MatrixBigDecimal.GLOBAL_SCALE;
                X[i][j] = X[i][j].subtract(X[k][j].multiply(QR[i][k], new MathContext(scale)));
            }
         }
      }
      return (new JamaMatrixBigDecimal(X,n,nx).getMatrix(0,n-1,0,nx-1));
   }
View Full Code Here

            return this;
        }
       
        for (int i = 0; i < this.matrix.length; i++) {
            for (int j = 0; j < this.matrix[0].length; j++) {
                this.matrix[i][j].round(new MathContext(digits));
            }
        }
       
        return this;
    }
View Full Code Here

            for (int j = 0; j < other.getRowCount(); j++) {
                for (int k = 0; k < this.getRowCount(); k++) {
                    if (c[i][j] == null) {
                        c[i][j] = BigDecimal.ZERO;
                    }
                    c[i][j] = c[i][j].add(this.get(i, k).multiply(other.get(k, j), new MathContext(GLOBAL_SCALE)));
                }
            }
        }

        this.matrix = c;
View Full Code Here

                precision--;
                formatToken.setPrecision(precision);
                transform_e();
                return;
            }
            BigDecimal b = new BigDecimal(d, new MathContext(precision));
            d = b.doubleValue();
            long l = b.longValue();

            if (d >= 1 && d < Math.pow(10, precision)) {
                if (l < Math.pow(10, precision)) {
View Full Code Here

            if (paymentApplication.get("paymentId") != null) {
                GenericValue payment = paymentApplication.getRelatedOne("Payment");
                if (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"))) {
                           appliedAmount = appliedAmount.multiply(payment.getBigDecimal("amount")).divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100));
                    }
                }
            }
        } catch (GenericEntityException e) {
            Debug.logError(e, "Problem getting Payment", module);
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.