Exemplo n.º 1
0
  public static RubyClass createFloatClass(Ruby runtime) {
    RubyClass floatc =
        runtime.defineClass(
            "Float", runtime.getNumeric(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    runtime.setFloat(floatc);

    floatc.setClassIndex(ClassIndex.FLOAT);
    floatc.setReifiedClass(RubyFloat.class);

    floatc.kindOf = new RubyModule.JavaClassKindOf(RubyFloat.class);

    floatc.getSingletonClass().undefineMethod("new");

    // Java Doubles are 64 bit long:
    floatc.defineConstant("ROUNDS", RubyFixnum.newFixnum(runtime, ROUNDS));
    floatc.defineConstant("RADIX", RubyFixnum.newFixnum(runtime, RADIX));
    floatc.defineConstant("MANT_DIG", RubyFixnum.newFixnum(runtime, MANT_DIG));
    floatc.defineConstant("DIG", RubyFixnum.newFixnum(runtime, DIG));
    // Double.MAX_EXPONENT since Java 1.6
    floatc.defineConstant("MIN_EXP", RubyFixnum.newFixnum(runtime, MIN_EXP));
    // Double.MAX_EXPONENT since Java 1.6
    floatc.defineConstant("MAX_EXP", RubyFixnum.newFixnum(runtime, MAX_EXP));
    floatc.defineConstant("MIN_10_EXP", RubyFixnum.newFixnum(runtime, MIN_10_EXP));
    floatc.defineConstant("MAX_10_EXP", RubyFixnum.newFixnum(runtime, MAX_10_EXP));
    floatc.defineConstant("MIN", RubyFloat.newFloat(runtime, Double.MIN_VALUE));
    floatc.defineConstant("MAX", RubyFloat.newFloat(runtime, Double.MAX_VALUE));
    floatc.defineConstant("EPSILON", RubyFloat.newFloat(runtime, EPSILON));

    floatc.defineConstant("INFINITY", RubyFloat.newFloat(runtime, INFINITY));
    floatc.defineConstant("NAN", RubyFloat.newFloat(runtime, NAN));

    floatc.defineAnnotatedMethods(RubyFloat.class);

    return floatc;
  }
Exemplo n.º 2
0
  public static RubyClass createIntegerClass(Ruby runtime) {
    RubyClass integer =
        runtime.defineClass(
            "Integer", runtime.getNumeric(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    runtime.setInteger(integer);

    integer.index = ClassIndex.INTEGER;
    integer.setReifiedClass(RubyInteger.class);

    integer.kindOf =
        new RubyModule.KindOf() {
          public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof RubyInteger;
          }
        };

    integer.getSingletonClass().undefineMethod("new");

    if (!runtime.is1_9()) {
      integer.includeModule(runtime.getPrecision());
    }

    integer.defineAnnotatedMethods(RubyInteger.class);

    return integer;
  }
Exemplo n.º 3
0
 public static RubyNumeric newNumeric(Ruby runtime) {
   return new RubyNumeric(runtime, runtime.getNumeric());
 }