Exemple #1
0
 public Fraction(BigDecimal original) {
   super();
   double A, C, D, X, Y, M;
   C = original.doubleValue();
   A = C;
   D = C;
   X = 1;
   Y = 0;
   do {
     M = Y;
     Y = X + Y * Math.round(C);
     X = M;
     if (C != Math.round(C)) {
       C = 1 / (C - Math.round(C));
     }
     M = Math.round(D * Y);
   } while (M != MathUtilities.toFix(D * Y, 10));
   if ((Math.abs(M) > 100000) || (Math.abs(Y) > 100000) || (Math.abs(Y) == 1)) {
     this.numerator = original;
     this.denominator = BigInteger.ONE;
   } else {
     this.numerator =
         BigDecimal.valueOf(Math.round((Math.abs(M) / M) * (Math.abs(Y) / Y) * Math.abs(M)));
     this.denominator = new BigInteger(Long.toString(Math.round(Math.abs(Y))));
   }
 }
Exemple #2
0
 @Override
 public String toString() {
   if (this.denominator.equals(BigInteger.ONE))
     return MathUtilities.formatNormalAnswer(this.numerator);
   else return this.numerator + "/" + this.denominator;
 }
Exemple #3
0
 public void tick(Velocity v) {
   int dx = (int) (MathUtilities.cosdeg(v.direction) * v.getSpeed());
   int dy = (int) (MathUtilities.sindeg(360 - v.direction) * v.getSpeed());
   this.x += dx;
   this.y += dy;
 }