Example #1
0
  @RubyLevelMethod(name = ">")
  public RubyValue opGt(RubyValue v) {
    if (v instanceof RubyFixnum) {
      return ObjectFactory.createBoolean(this.value_ > ((RubyFixnum) v).value_);
    } else if (v instanceof RubyFloat) {
      return ObjectFactory.createBoolean(this.value_ > v.toFloat());
    }

    return coerceRelop(RubyID.gtID, v);
  }
Example #2
0
  @RubyLevelMethod(name = "-")
  public RubyValue opMinus(RubyValue v) {
    if (v instanceof RubyFixnum) {
      return RubyBignum.bignorm((long) this.value_ - (long) ((RubyFixnum) v).value_);
    }

    if (v instanceof RubyFloat) {
      return ObjectFactory.createFloat(this.value_ - v.toFloat());
    }

    if (v instanceof RubyBignum) {
      BigInteger bigValue1 = BigInteger.valueOf(this.value_);
      BigInteger bigValue2 = ((RubyBignum) v).getInternal();
      return RubyBignum.bignorm(bigValue1.subtract(bigValue2));
    }

    return coerceBin(RubyID.subID, v);
  }
Example #3
0
  @RubyLevelMethod(name = "**")
  public RubyValue pow(RubyValue v) {
    if (v instanceof RubyFixnum) {
      int p = ((RubyFixnum) v).value_;
      if (p == 0) {
        return ObjectFactory.FIXNUM1;
      } else if (p == 1) {
        return this;
      }

      if (p > 0) {
        BigInteger b = BigInteger.valueOf(this.value_);
        return RubyBignum.bignorm(b.pow(p));
      }

      return ObjectFactory.createFloat(Math.pow(this.value_, p));
    } else if (v instanceof RubyFloat) {
      return ObjectFactory.createFloat(Math.pow(this.value_, v.toFloat()));
    }

    return coerceBin(RubyID.powID, v);
  }
Example #4
0
 @RubyLevelMethod(name = "/")
 public RubyValue opDiv(RubyValue v) {
   if (v instanceof RubyFixnum) {
     int intValue1 = this.value_;
     int intValue2 = ((RubyFixnum) v).value_;
     if (intValue2 == 0) {
       zeroDiv();
     }
     int div = intValue1 / intValue2;
     int mod = intValue1 - div * intValue2;
     if (mod != 0 && div < 0) {
       --div;
     }
     return RubyBignum.bignorm(div);
   } else if (v instanceof RubyFloat) {
     return ObjectFactory.createFloat(this.value_ / v.toFloat());
   } else if (v instanceof RubyBignum) {
     BigInteger bigValue1 = BigInteger.valueOf(this.value_);
     BigInteger bigValue2 = ((RubyBignum) v).getInternal();
     return RubyBignum.bignorm(bigValue1.divide(bigValue2));
   } else {
     return coerceBin(RubyID.divID, v);
   }
 }