コード例 #1
0
ファイル: RubyString.java プロジェクト: sumitk/rhodes
 // @RubyLevelMethod(name="to_f")
 public RubyFloat toRubyFloat() {
   double d;
   try {
     d = this.toFloat();
   } catch (NumberFormatException e) {
     throw new RubyException(RubyRuntime.ArgumentErrorClass, e.toString());
   }
   return ObjectFactory.createFloat(d);
 }
コード例 #2
0
ファイル: RubyFixnum.java プロジェクト: rzel/xruby
  @RubyLevelMethod(name = "quo")
  public RubyFloat quo(RubyValue v) {
    if (v instanceof RubyFixnum) {
      return ObjectFactory.createFloat(this.value_ / ((RubyFixnum) v).value_);
    }

    // FIXME: should be coerced.
    throw new RubyException(
        RubyRuntime.TypeErrorClass, v.getRubyClass().getName() + " can't be coersed into Fixnum");
  }
コード例 #3
0
ファイル: RubyFixnum.java プロジェクト: rzel/xruby
  @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);
  }
コード例 #4
0
ファイル: RubyFixnum.java プロジェクト: rzel/xruby
  @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);
  }
コード例 #5
0
ファイル: RubyFixnum.java プロジェクト: rzel/xruby
 @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);
   }
 }
コード例 #6
0
ファイル: RubyFixnum.java プロジェクト: rzel/xruby
 public RubyFloat toRubyFloat() {
   return ObjectFactory.createFloat(this.value_);
 }
コード例 #7
0
ファイル: RubyFixnum.java プロジェクト: rzel/xruby
 @RubyLevelMethod(name = "to_f")
 public RubyFloat convertToFloat() {
   return ObjectFactory.createFloat(this.value_);
 }