Top Description Inners Fields Constructors Methods
org.jruby

public Class RubyNumeric

extends RubyObject
Class Inheritance
Known Direct Subclasses
org.jruby.RubyRational, org.jruby.ext.bigdecimal.RubyBigDecimal, org.jruby.RubyComplex, org.jruby.RubyFloat, org.jruby.RubyInteger
Annotations
@JRubyClass
name:Numeric
include:Comparable
Imports
org.jruby.RubyEnumerator.SizeFn, org.jruby.anno.JRubyClass, .JRubyMethod, org.jruby.api.JRubyAPI, org.jruby.ast.util.ArgsUtil, org.jruby.exceptions.RaiseException, org.jruby.javasupport.JavaUtil, org.jruby.runtime.Arity, .Block, .CallSite, .ClassIndex, .Helpers, .JavaSites, .ThreadContext, .Visibility, org.jruby.runtime.builtin.IRubyObject, org.jruby.util.ByteList, .ConvertBytes, .ConvertDouble, .TypeConverter, java.math.BigDecimal, .BigInteger, .RoundingMode

Base class for all numerical types in ruby.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
private static class

Field Summary

Modifier and TypeField and Description
public static final double
private static final String[]
Inherited from org.jruby.RubyObject:
IVAR_INSPECTING_OBJECT_ALLOCATOROBJECT_ALLOCATORREIFYING_OBJECT_ALLOCATOR

Constructor Summary

AccessConstructor and Description
public
RubyNumeric(Ruby runtime, RubyClass metaClass)

public
public
RubyNumeric(Ruby runtime, RubyClass metaClass, boolean useObjectSpace)

public
RubyNumeric(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted)
Deprecated

Method Summary

Modifier and TypeMethod and Description
public IRubyObject
abs(ThreadContext context)

num_abs

public IRubyObject
abs2(ThreadContext context)

numeric_abs2

public IRubyObject
arg(ThreadContext context)

numeric_arg

public BigInteger

Returns:

a BigInteger
asBigInteger
(ThreadContext
the current thread context
context
)

Return a BigInteger representation of this numerical value

public double

Returns:

a double
asDouble
(ThreadContext
the current thread context
context
)

Return a double representation of this numerical value

public int
asInt(ThreadContext context)

Returns the value of this numeric and a java int.

public long
asLong(ThreadContext context)

Return the value of this numeric as a 64-bit long.

public RubyNumeric
protected final IRubyObject
callCoerced(ThreadContext context, String method, IRubyObject other, boolean err)

public final IRubyObject
callCoerced(ThreadContext context, String method, IRubyObject other)

protected final IRubyObject
callCoerced(ThreadContext context, CallSite site, IRubyObject other, boolean err)

public final IRubyObject
public IRubyObject
ceil(ThreadContext context)

MRI: num_ceil

public IRubyObject
ceil()
Deprecated

public static int
checkInt(final Ruby runtime, long num)

check_int

public static void
checkInt(IRubyObject arg, long num)

private static void
checkIntFail(Ruby runtime, long num)

public IRubyObject
public IRubyObject
coerce(ThreadContext context, IRubyObject other)

num_coerce

protected final IRubyObject
coerceBin(ThreadContext context, String method, IRubyObject other)
Deprecated

rb_num_coerce_bin coercion taking two arguments

protected final IRubyObject
protected final IRubyObject
coerceBit(ThreadContext context, String method, IRubyObject other)

rb_num_coerce_bit coercion taking two arguments

protected final IRubyObject
private static IRubyObject
coerceBitRecursive(ThreadContext context, JavaSites.CheckedSites site, IRubyObject _array, boolean recur)

protected final IRubyObject
coerceCmp(ThreadContext context, String method, IRubyObject other)
Deprecated

rb_num_coerce_cmp coercion used for comparisons

protected final IRubyObject
protected final void
coerceFailed(ThreadContext context, IRubyObject arg)

coerce_failed

protected final IRubyObject
coerceRelOp(ThreadContext context, String method, IRubyObject other)
Deprecated

rb_num_coerce_relop coercion used for relative operators

protected final IRubyObject
protected final IRubyObject
coerceRescue(ThreadContext context, IRubyObject other)

coerce_rescue

private static RubyArray<T extends IRubyObject>
coerceResult(ThreadContext context, final IRubyObject result, final boolean err)

pack-priv static IRubyObject
protected static IRubyObject
public IRubyObject
conjugate(ThreadContext context)

numeric_real

public RubyRational
convertToRational()
Deprecated since 10.0.

public RubyRational
public static RubyClass
public static RubyInteger
dbl2ival(Ruby runtime, double val)
Deprecated since 10.0. Use org.jruby.api.Convert#asInteger(ThreadContext, double) instead.

public static IRubyObject
dbl2num(Ruby runtime, double val)
Deprecated since 10.0. Use org.jruby.api.Convert#asFloat(ThreadContext, long) instead.

public static IRubyObject
dbl_cmp(Ruby runtime, double a, double b)

rb_dbl_cmp (numeric.c)

public IRubyObject
denominator(ThreadContext context)

numeric_denominator

public IRubyObject
div(ThreadContext context, IRubyObject other)

MRI: num_div

public IRubyObject
divmod(ThreadContext context, IRubyObject other)

num_divmod

protected final RubyArray<T extends IRubyObject>
doCoerce(ThreadContext context, IRubyObject other, boolean err)

do_coerce

private static void
duckStep(ThreadContext context, IRubyObject from, IRubyObject to, IRubyObject step, boolean inf, boolean desc, Block block)

public IRubyObject
public IRubyObject
public IRubyObject
fdiv(ThreadContext context, IRubyObject other)

num_fdiv

public IRubyObject
public static int
fix2int(IRubyObject arg)
Deprecated since 10.0.

public static int
fix2int(RubyFixnum arg)
Deprecated since 10.0.

public static long
fix2long(IRubyObject arg)
Deprecated since 10.0. Use RubyFixnum#getValue()

public static boolean
fixable(Ruby runtime, double f)

private static void
fixnumStep(ThreadContext context, RubyFixnum from, IRubyObject to, RubyFixnum step, boolean inf, boolean desc, Block block)

public static long
float2long(RubyFloat flt)
Deprecated since 10.0.

public static long

Returns:

an unsigned long encoded as a signed long, or raise an error if out of range
float2ulong
(RubyFloat
the argument to convert
flt
)

Convert the given RubyFloat into an unsigned long, encoded as a signed long.

public static boolean
floatStep(ThreadContext context, IRubyObject from, IRubyObject to, IRubyObject step, boolean excl, boolean allowEndless, Block block)

public static double
floatStepSize(double beg, double end, double unit, boolean excludeLast)

Returns the number of unit-sized steps between the given beg and end.

public IRubyObject
floor(ThreadContext context)

MRI: num_floor

public IRubyObject
floor()
Deprecated

public BigInteger
getBigIntegerValue()
Deprecated since 10.0.

protected final IRubyObject[]
getCoerced(ThreadContext context, IRubyObject other, boolean error)

Numeric methods.

public double
getDoubleValue()
Deprecated since 10.0. Use org.jruby.RubyNumeric#asDouble(ThreadContext) instead.

public int
getIntValue()
Deprecated since 10.0. Use org.jruby.RubyNumeric#asInt(ThreadContext) instead.

Return the value of this numeric as a 32-bit long.

public long
getLongValue()
Deprecated since 10.0. Use org.jruby.RubyNumeric#asLong(ThreadContext) instead.

Return the value of this numeric as a 64-bit long.

public static RoundingMode
public IRubyObject
idiv(ThreadContext context, IRubyObject other)

MRI: rb_int_idiv and overrides

public IRubyObject
idiv(ThreadContext context, long other)

public IRubyObject
image(ThreadContext context)

numeric_image

public IRubyObject
public IRubyObject
initialize_copy(ThreadContext
the thread context
context
,
IRubyObject
the original
arg
)

Overrides org.jruby.RubyBasicObject.initialize_copy.

num_init_copy

public static RubyNumeric
int2fix(Ruby runtime, long val)
Deprecated since 10.0. Use org.jruby.api.Convert#asFixnum(ThreadContext, long) instead.

public IRubyObject
integer_p()
Deprecated since 10.0.

public IRubyObject
integer_p(ThreadContext context)

num_int_p

public static RubyNumeric
intervalStepSize(ThreadContext context, IRubyObject from, IRubyObject to, IRubyObject step, boolean excl)

public IRubyObject
isNegative(ThreadContext context)

num_negative_p

public boolean
public boolean
public IRubyObject
isPositive(ThreadContext context)

num_positive_p

public boolean
public boolean
public boolean
public boolean
isZero()
Deprecated since 10.0. Use org.jruby.RubyNumeric#isZero(ThreadContext) instead.

public boolean
public IRubyObject
magnitude(ThreadContext context)

num_abs/1.9

public IRubyObject
modulo(ThreadContext context, IRubyObject other)

num_modulo

pack-priv IRubyObject
modulo(ThreadContext context, long other)

public static boolean
public static boolean
public static boolean
negFixable(double l)

public static RubyNumeric
newNumeric(Ruby runtime)

public IRubyObject
nonzero_p(ThreadContext context)

num_nonzero_p

public static byte
num2chr(IRubyObject arg)
Deprecated since 10.0.

NUM2CHR

public static double
public static double
num2dbl(ThreadContext context, IRubyObject arg)

rb_num2dbl and NUM2DBL

public static IRubyObject
num2fix(IRubyObject val)
Deprecated since 10.0.

public static IRubyObject
num2fix(ThreadContext context, IRubyObject val)
Deprecated since 10.0.

public static int
num2int(IRubyObject arg)
Deprecated since 10.0.

rb_num2int, NUM2INT if you know it is Integer use org.jruby.api.Convert#toInt(ThreadContext, IRubyObject).

public static long
num2long(IRubyObject arg)

rb_num2long and FIX2LONG (numeric.c)

public static long

Returns:

an unsigned long encoded as a signed long, or raise an error if out of range
num2ulong
(IRubyObject
the argument to convert
arg
)

Convert the given value into an unsigned long, encoded as a signed long.

public IRubyObject
num_imaginary(ThreadContext context)

num_imaginary

public IRubyObject
numerator(ThreadContext context)

numeric_numerator

private int
numExtractStepArgs(ThreadContext context, IRubyObject[] args, IRubyObject[] newArgs)

MRI: num_step_extract_args

public static IRubyObject
public static IRubyObject
numFuncall(ThreadContext context, final IRubyObject x, CallSite site, final IRubyObject value)

private static IRubyObject
numFuncall0(ThreadContext context, CallSite site, IRubyObject obj, boolean recur)

public IRubyObject
private boolean
numStepCheckFixArgs(ThreadContext context, int argc, IRubyObject[] newArgs, IRubyObject by)

MRI: num_step_check_fix_args

private static boolean
public IRubyObject
public IRubyObject
public IRubyObject
protected final IRubyObject
op_num_equal(ThreadContext context, IRubyObject other)

num_equal, doesn't override RubyObject.op_equal

public IRubyObject
public IRubyObject
op_uminus(ThreadContext context)

num_uminus

public IRubyObject
op_uplus()
Deprecated since 10.0.

public IRubyObject
op_uplus(ThreadContext context)

num_uplus

private static long
other2long(IRubyObject arg)
Deprecated since 10.0.

public IRubyObject
polar(ThreadContext context)

numeric_polar

public static boolean
public static boolean
posFixable(double l)

public static boolean
public IRubyObject
quo(ThreadContext context, IRubyObject other)

num_quo

public final IRubyObject
rbClone(IRubyObject[] args)
Deprecated

public final IRubyObject
public final IRubyObject
public final IRubyObject
public IRubyObject
real(ThreadContext context)

numeric_real

public IRubyObject
real_p(ThreadContext context)

num_real_p

public IRubyObject
rect(ThreadContext context)

numeric_rect

public IRubyObject
remainder(ThreadContext context, IRubyObject y)

num_remainder

public IRubyObject
round(ThreadContext context)

MRI: num_round

public IRubyObject
round()
Deprecated

public IRubyObject
scalar_p()
Deprecated

private boolean
scanStepArgs(ThreadContext context, IRubyObject[] args, IRubyObject[] newArgs)

MRI: num_step_scan_args

public static IRubyObject
private static JavaSites.NumericSites
sites(ThreadContext context)

Hides org.jruby.RubyObject.sites.

Retrieve the call sites for this class.

public IRubyObject
step(ThreadContext context, IRubyObject[] args, Block block)

num_step

private IRubyObject
stepCommon(ThreadContext context, IRubyObject to, IRubyObject step, boolean desc, Block block)

private static IRubyObject
stepSize(ThreadContext context, RubyNumeric from, IRubyObject[] args)

A step size method suitable for lambda method reference implementation of SizeFn#size(ThreadContext, IRubyObject, IRubyObject[]) MRI: num_step_size

public static RubyFloat

Returns:

a RubyFloat representing the result of the conversion, which will be 0.0 if the conversion failed.
str2fnum
(Ruby
the ruby runtime
runtime
,
RubyString
the string to be converted
arg
)

Same as RubyNumeric.str2fnum passing false for strict.

public static IRubyObject

Returns:

a RubyFloat representing the result of the conversion, which will be 0.0 if the conversion failed.
str2fnum
(Ruby
the ruby runtime
runtime
,
RubyString
the string to be converted
arg
,
boolean
if true, enforce the strict criteria for String encoding of numeric values, as required by Float('n'), and raise an exception when those criteria are not met. Otherwise, allow lax expression of values, as permitted by String#to_f, and return a value in all cases.

Todo

describe the rules/criteria

strict
,
boolean exception)

Converts a string representation of a floating-point number to the numeric value.

public static RubyFloat
str2fnum(Ruby runtime, RubyString arg, boolean strict)

public static RubyInteger
str2inum(Ruby runtime, RubyString str, int base)
Deprecated since 10.0.

public static IRubyObject

Returns:

a RubyFixnum or (if necessary) a RubyBignum representing the result of the conversion, which will be zero if the conversion failed.
str2inum
(Ruby
the ruby runtime
runtime
,
RubyString
the string to be converted
str
,
int
the expected base of the number (for example, 2, 8, 10, 16), or 0 if the method should determine the base automatically (defaults to 10). Values 0 and 2-36 are permitted. Any other value will result in an ArgumentError.
base
,
boolean
if true, enforce the strict criteria for String encoding of numeric values, as required by Integer('n'), and raise an exception when those criteria are not met. Otherwise, allow lax expression of values, as permitted by String#to_i, and return a value in almost all cases (excepting illegal radix).

Todo

describe the rules/criteria

strict
,
boolean exception)

Converts a string representation of an integer to the integer value.

public static RubyInteger
str2inum(Ruby runtime, RubyString str, int base, boolean strict)
Deprecated since 10.0.

public IRubyObject
to_c(ThreadContext context)

numeric_to_c

public IRubyObject
to_int(ThreadContext context)

num_to_int

public <T> T
toJava(Class<T>
The target type to which the object should be converted.
target
)

Overrides org.jruby.RubyBasicObject.toJava.

Implements org.jruby.runtime.builtin.IRubyObject.toJava.

Convert the object to the specified Java class, if possible.

public IRubyObject
truncate(ThreadContext context)

MRI: num_truncate

public IRubyObject
truncate()
Deprecated

num_truncate

private IRubyObject
unwrapCoerced(ThreadContext context, String method, IRubyObject other, RubyArray<T extends IRubyObject> ary)

private IRubyObject
unwrapCoerced(ThreadContext context, CallSite site, IRubyObject other, RubyArray<T extends IRubyObject> ary)

public IRubyObject
zero_p(ThreadContext context)

num_zero_p

Inherited from org.jruby.RubyObject:
attachToObjectSpacecallInitcallInitcallInitcallInitcallInitcallInitcallInitcallInitcallInitcallInitconvertToTypedigdig1dig2eqlInternalequalInternalequalsfinishObjectClassgetNativeClassIndexhashCodeinspectop_eqqputsspecificEvaltoRubyStringtoString