/** * Return the value of this numeric as a 32-bit long. If the value does not * fit in 32 bits, it will be truncated. */ public int getIntValue() { return (int) getLongValue(); }
@Override public IRubyObject size(IRubyObject[] args) { long n = self.realLength; assert args != null && args.length > 0 && args[0] instanceof RubyNumeric; // #repeated_combination ensures arg[0] is numeric long k = ((RubyNumeric) args[0]).getLongValue(); if (k == 0) { return RubyFixnum.one(context.runtime); } return binomialCoefficient(context, k, n + k - 1); } };
public long size() { final IRubyObject size = size(null); if ( size instanceof RubyNumeric ) { return ((RubyNumeric) size).getLongValue(); } return -1; }
public int getInt(String propertyName, Object... args) { IRubyObject result = getRubyProperty(propertyName, args); if (result instanceof RubyNil) { return 0; } else { return (int) ((RubyNumeric) result).getLongValue(); } }
public long size() { final IRubyObject size = size(null); if ( size instanceof RubyNumeric ) { return ((RubyNumeric) size).getLongValue(); } return -1; }
public Object convert(ThreadContext context, IRubyObject rubyObject) { if (rubyObject.respondsTo("to_i")) { return Short.valueOf((short) ((RubyNumeric) rubyObject.callMethod( context, "to_i")).getLongValue()); } return Short.valueOf((short) 0); } };
public Object convert(ThreadContext context, IRubyObject rubyObject) { if (rubyObject.respondsTo("to_i")) { return Character.valueOf((char) ((RubyNumeric) rubyObject.callMethod( context, "to_i")).getLongValue()); } return Character.valueOf((char) 0); } };
public Object convert(ThreadContext context, IRubyObject rubyObject) { if (rubyObject.respondsTo("to_i")) { return Character.valueOf((char) ((RubyNumeric) rubyObject.callMethod( context, "to_i")).getLongValue()); } return Character.valueOf((char) 0); } };
public Object coerce(RubyNumeric numeric, Class target) { long value = numeric.getLongValue(); if (isLongShortable(value)) { return Short.valueOf((short)value); } throw numeric.getRuntime().newRangeError("too big for short: " + numeric); } };
public Object convert(ThreadContext context, IRubyObject rubyObject) { if (rubyObject.respondsTo("to_i")) { return (byte) ((RubyNumeric) rubyObject.callMethod(context, "to_i")).getLongValue(); } return (byte) 0; } };
public Object convert(ThreadContext context, IRubyObject rubyObject) { if (rubyObject.respondsTo("to_i")) { return (int) ((RubyNumeric) rubyObject.callMethod(context, "to_i")).getLongValue(); } return (int) 0; } };
public Object convert(ThreadContext context, IRubyObject rubyObject) { if (rubyObject.respondsTo("to_i")) { return (short) ((RubyNumeric) rubyObject.callMethod(context, "to_i")).getLongValue(); } return (short) 0; } };
public Object convert(ThreadContext context, IRubyObject rubyObject) { if (rubyObject.respondsTo("to_i")) { return (char) ((RubyNumeric) rubyObject.callMethod(context, "to_i")).getLongValue(); } return (char) 0; } };
public Object convert(ThreadContext context, IRubyObject rubyObject) { if (rubyObject.respondsTo("to_i")) { return (short) ((RubyNumeric) rubyObject.callMethod(context, "to_i")).getLongValue(); } return (short) 0; } };
public Object convert(ThreadContext context, IRubyObject rubyObject) { if (rubyObject.respondsTo("to_i")) { return (char) ((RubyNumeric) rubyObject.callMethod(context, "to_i")).getLongValue(); } return (char) 0; } };
public Object convert(ThreadContext context, IRubyObject rubyObject) { if (rubyObject.respondsTo("to_i")) { return (byte) ((RubyNumeric) rubyObject.callMethod(context, "to_i")).getLongValue(); } return (byte) 0; } };
int intValue(IRubyObject obj) { if (obj instanceof RubyNumeric) return (int)((RubyNumeric)obj).getLongValue(); // basically just forcing a TypeError here to match MRI obj = TypeConverter.convertToType(obj, obj.getRuntime().getFixnum(), "to_int", true); return (int)((RubyFixnum)obj).getLongValue(); }
@Override public IRubyObject size(IRubyObject[] args) { RubyFixnum n = self.length(); assert args != null && args.length > 0 && args[0] instanceof RubyNumeric; // #repeated_permutation ensures arg[0] is numeric long k = ((RubyNumeric) args[0]).getLongValue(); if (k < 0) { return RubyFixnum.zero(runtime); } RubyFixnum v = RubyFixnum.newFixnum(runtime, k); return op_exp.call(context, n, n, v); } };
int intValue(IRubyObject obj) { if (obj instanceof RubyNumeric) return (int)((RubyNumeric)obj).getLongValue(); // basically just forcing a TypeError here to match MRI obj = TypeConverter.convertToType(obj, obj.getRuntime().getFixnum(), "to_int", true); return (int)((RubyFixnum)obj).getLongValue(); }
int intValue(IRubyObject obj) { if (obj instanceof RubyNumeric) return (int)((RubyNumeric)obj).getLongValue(); // basically just forcing a TypeError here to match MRI obj = TypeConverter.convertToType(obj, obj.getRuntime().getFixnum(), "to_int", true); return (int)((RubyFixnum)obj).getLongValue(); }