Examples of MathContext


Examples of java.math.MathContext

  System.out.println(b3.scale());      // 101
  System.out.println(b3.signum());     // -1

  // RoundingMode.DOWN always goes towards 0
  // b3.precision() - b3.scale() will be the number of digits in the integer part of the BigDecimal
  MathContext mc = new MathContext(b3.precision() - b3.scale(), RoundingMode.DOWN);
  BigDecimal b3ROUNDED = b3.round(mc);
  BigDecimal b3FRACTIONALPART = b3.subtract(b3ROUNDED);
 
  System.out.println(b3ROUNDED);       // -22222222222222222222222222222222222222222222222222222222222222222222222
  System.out.println(b3FRACTIONALPART); // -0.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
View Full Code Here

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

Examples of java.math.MathContext

         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

Examples of java.math.MathContext

      // 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

Examples of java.math.MathContext

   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

Examples of java.math.MathContext

            // 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

Examples of java.math.MathContext

      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

Examples of java.math.MathContext

            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

Examples of java.math.MathContext

            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

Examples of java.math.MathContext

                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
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.